Thoughts and problems with "Align ...

Anonymous
2012-08-29
2017-01-27
  • Anonymous - 2012-08-29

    This should probably be a bug report (or two), but since the formatting can be
    done better in this forum I'd like to open a discussion.

    Let us have the following code:

    \begin{tabular}{rcl}
        Col 1 & Col 2 & Col 3 \\
        some content... & more content... & a lot of content ... \\
    \end{tabular}
    

    Using the "Align Columns" function (button/menu/shortcut) we get:

    \begin{tabular}{rcl}
                  Col 1 &      Col 2      & Col 3                \\
        some content... & more content... & a lot of content ... \\
    \end{tabular}
    

    Great! It does align the columns' content according to the column
    specification (rcl). :)

    1. Parameters and commands following the linebreak command
    For the next step, I want a horizontal line between those two rows (\hline)
    and I need to append something to the third column's header:

    \begin{tabular}{rcl}
                  Col 1 &      Col 2      & Col 3 (Notes)               \\ \hline
        some content... & more content... & a lot of content ... \\
    \end{tabular}
    

    After aligning via "Align Columns" I have:

    \begin{tabular}{rcl}
                  Col 1 &      Col 2      & Col 3 (Notes)        \\
    \hline
        some content... & more content... & a lot of content ... \\
    \end{tabular}
    

    This is the first think I dislike: The algorithm moves everything after "\"
    to a blank line.
    Even an optional parameter as in

    \\[1ex]
    

    to add more space will be separated:

    \begin{tabular}{rcl}
                                Col 1 &      Col 2      & Col 3 (Notes)        \\
        [1ex]
    \hline
        some content... & more content... & a lot of content ... \\
    \end{tabular}
    

    Notice the missing indention before \hline. This blows the code up
    unnecessarily.

    Furthermore, when using the standard package booktabs a simple tabular like

    \begin{tabular}{rcl}
        \toprule
                  Col 1 &      Col 2      & Col 3 (Notes)        \\\midrule
        some content... & more content... & a lot of content ... \\\bottomrule
    \end{tabular}
    

    gets "aligned" to:

    \begin{tabular}{rcl}
        \toprule
                  Col 1 &      Col 2      & Col 3 (Notes)        \\
        \midrule
        some content... & more content... & a lot of content ... \\
                      \bottomrule &  \\
    \end{tabular}
    

    Notice the indention before \bottomrule, the extra ampersand and the linebreak
    command!
    Suggestion: Leave text behind the linebreak command alone and don't add more
    linebreaks.

     
  • Anonymous - 2012-08-29

    2. Column specification
    For example, the siunitx package provides the column specification \"S\" (for
    numbers) and \"s\" (for units):

    \\begin{tabular}{rcS}
                  Col 1 &      Col 2      & 123.45 \\\\
        some content... & more content... & 7.897  \\\\
    \\end{tabular}
    

    Both can have an optional parameter with key-value instructions. Texstudio
    seems to \"see\" another column when one uses the \"Align Columns\" function:

    \\begin{tabular}{rcS[key=value]}
                  Col 1 &      Col 2      & 123.45 &  \\\\
        some content... & more content... & 7.897  &  \\\\
    \\end{tabular}
    

    Notice the extra ampersand.
    Suggestion: _Treat as a parameter (similar to {} in p{2cm}). Bonus: Align S
    columns at the decimal separator (can be a period and a comma). _

    3. Alignment in math environments like align, alignat etc.
    As discussed in a previous feature request (Alignment of tables and equations
    at ampersand), I talked about problems with \intertext and the like.
    The alignment algorithm stopped working in math environments a long time ago.
    Are there any specific reasons for dropping this feature?

     
  • Anonymous - 2012-08-29

    4. Line Wrapping
    When handling tabulars (or math) environments the contents can get very long
    (using a lot of formatting commands and the like).
    Normally, I use soft line wrapping but for tabulars and/or math environments I
    would like to switch to no line wrapping and scroll horizontally.
    See the following (although contrived) example:

    I don't have a solution for this problem aside from manual formatting.
    Maybe: Shortcut for switching between soft and no line wrapping

     
  • Anonymous - 2012-08-29

    Post Scriptum:
    1. The optional argument even produces not aligned ampersands.
    2. I don't know why the second post has escape characters (multiple backshlashes) added to it.
    3. I had to split my post because the forum software "sensed" spam and I didn't know where.
    4. It is very annoying to work with the sourceforge interface.

     
  • Tim Hoffmann

    Tim Hoffmann - 2012-08-29

    Thanks for the comments. I will consider them.

    The Align-Table function is more a proof-of-concept right now. You may
    imagine, that parsing table code and also formating (multicolumn) can de quite
    complex. The current version works for a reasonable set of cases, but is far
    from beeing complete (and likely never will, considering the complexity of
    latex). It's designed to be extendable. However, you have to know all the
    possible cases and handle them correctly.

    Furthermore people have different ways of formating: \hline at beginning/end
    of a line/on a separate line; one column per line for large tables... It's not
    something you can make right for all people. Maybe I'll add configuration
    possibilities later.

     
  • Tim Hoffmann

    Tim Hoffmann - 2012-08-29

    Concerning the sf interface: It's not good, but it's all we have right now. sf
    will migrate to a new interface later this year. Hopefully things will get
    better then.

     
  • Anonymous - 2012-08-29

    t_hoffman
    You may imagine, that parsing table code and also formating (multicolumn) can
    de quite complex. It's not something you can make right for all people.

    This is one of the reason I didn't post this on the bug tracker but rather in
    the "Open Discussion" forum.
    There are too many possibilities that can mess up the algorithm.

    By the way, the following code shows a kind of workaround I often use (this is
    also a good way to comment columns):

    \begin{tabular}{rcl}
             \toprule % &                 &  \\
                  Col 1 &      Col 2      & Col 3 (Notes)        \\
             \midrule % &                 &  \\
        some content... & more content... & a lot of content ... \\
          \bottomrule % &                 &  \\
    \end{tabular}
    

    As far as I know, there aren't many (La)TeX editors out there that support
    automatic alignment. This is still better than nothing.

     
  • Tim Hoffmann

    Tim Hoffmann - 2012-10-01

    Issues 1 and 2 should now be fixed (rev. 3334). Also there are now options to
    specify some parameters of the alignment. They are located in Configure ->
    Advanced Editor.

    Issue 3: Alignment in math enviroments: Did it ever work? At least I did not
    officially write support for this so far. But is might have worked in a very
    early version, before the parser was changed to set up a complete model of the
    table.

    Issue 4: Line Wrapping. I don't have a solution for this either.
    @Shortcut for wrapping: It's currently not possible to make options available
    as menus/toolbar entries/shortcuts
    At least, there is now an option to format with one line per cell.

     
  • Richard Niland

    Richard Niland - 2017-01-27

    The alignment feature is something that had colleagues of mine stare at my screen with unbelieving eyes, saying "Hold on... you just push a button and the entire table becomes aligned neatly? I'll have to switch editors" -- so, great job on that front so far!

    I was especially glad to see that even multicolumns align perfectly.

    However, I'd like to add some new reports and suggestions to the old ones:


    Issue 1:
    When using the \cmidrules from booktabs, the alignment algorithm fails spectacularly.
    Maybe it'd be possible to specify parameterized commands for table formatting alongside unparametrized ones such as \hline?


    Issue 4:
    I just had a spontaneous idea that's most likely horribly complicated to implement:
    Have different line wrapping settings for select environments, i.e., allow users to add their desired environments to a list, similar to the alignment commands for tables, and allow for a different line wrapping setting that only applies to code between \begin{envirenment} and \end{environment}.

    Since that would probably already require splitting the text field into several fields already, it should then not be too had to, for example, have different horizontal scrolling in those areas.
    What I'm thinking of here is something along the lines of having regular text that soft-wraps at the text area edge, and tabulars that don't wrap -- but when I scroll to the right, the regular text will remain on-screen, and only the tabular contents will move.


    Some other spontaneous ideas for a UX improvement feature:

    • When the cursor is in a specific cell, the corresponding column's descriptor in the tabular header is highlighted.
    • The "align table" button is not a one-time button but rather an on/off-switch, and when it's on, alignment will happen in real-time.
     
    Last edit: Richard Niland 2017-01-27
  • Jan  Sundermeyer

    Jan Sundermeyer - 2017-01-27

    well, you are wellcome to provide code patches

     
  • Tim Hoffmann

    Tim Hoffmann - 2017-01-27

    @Issue 1:
    There's an open feature request: https://sourceforge.net/p/texstudio/feature-requests/601/

    @Issue 4:
    Environment-dependent line wrapping has also been requested before: https://sourceforge.net/p/texstudio/feature-requests/1109/

    Since that would probably already require splitting the text field into several fields already, it should then not be too had to, for example, have different horizontal scrolling in those areas.

    No, the first step is to make the wrapping algorithm context dependent. This is difficult enough (no idea if this will be implemented ever). Different scrollings would be a significant additional complication.

     


Anonymous

Cancel  Add attachments