3

Edit: Modified the MWE and tried to give a better description of my problem

I'd like to be able to align columns under a multicolumn column header.

In the MWE I've just the data in the first table, and it appears how I expect it too, in the second table I've added a long column header.

I'd like to be able to modify the final two columns, such that the vertical divider appears midway through the "Very Long Column Name", and the final column in the last row does not get pushed into the center of the column.

This is the current output of the MWE This is the current output of the MWE

While this is what I'm after... While this is what I'm after...

Thanks in advance!

\documentclass{article}

\usepackage[separate-uncertainty=true]{siunitx}

\begin{document}
  \begin{tabular}{l c l|l}
    Row 1 & & a  & b \\
    Row 2 & & \tablenum[table-format = 1.1]{1.2} & \tablenum[table-format = 1.1]{3.4} \\
  \end{tabular} \\

  \begin{tabular}{l c l|l}
    \multicolumn{1}{c}{Column Name} & \phantom{} & \multicolumn{2}{c}{Very Long Column Name} \\
    Row 1 & & a  & b \\
    Row 2 & & \tablenum[table-format = 1.1]{1.2} & \tablenum[table-format = 1.1]{3.4} \\
  \end{tabular}
\end{document}
  • Are line breaks allowed in the string "Very Long Column Name", or must the combined column be at least as wide as this string? Please advise. – Mico Sep 11 '17 at 19:16
  • Welcome to TeX SX! How is \tablenum defined? – Bernard Sep 11 '17 at 19:19
  • @Mico, I cannot add line breaks the column names. – Andy Sep 11 '17 at 19:21
  • @Bernard, \tablenum comes from the siunitx package, it's not mine. – Andy Sep 11 '17 at 19:23
  • What does "cannot" mean here? Do you mean "want not", or do you mean to say that you don't know how to insert line breaks? – Mico Sep 11 '17 at 19:23
3

Like the second tabular here?

\documentclass{article}
\usepackage{graphicx}
\usepackage[separate-uncertainty=true]{siunitx}

\begin{document}
    \begin{tabular}{l c l|l}
        Row 1 & & a  & b \\
        Row 2 & & \tablenum[table-format = 1.1]{1.2} & \tablenum[table-format = 1.1]{3.4} \\
    \end{tabular} \\

    \begin{tabular}{l c}
        Column Name & Very Long Column Name \\
        \begin{tabular}{@{}l@{}}
            Row 1\\
            Row 2\\
        \end{tabular}
        &
        \begin{tabular}{@{}r|l@{}}
             a  & b \\
            \tablenum[table-format = 1.1]{1.2} & \tablenum[table-format = 1.1]{3.4} \\
        \end{tabular}
    \end{tabular}
\end{document}

enter image description here

  • Yes! Changing the @{}r|l@{} to @{}l|l@{} gives me exactly what I'm after! – Andy Sep 11 '17 at 21:02

Your Answer

By clicking “Post Your Answer”, you agree to our terms of service, privacy policy and cookie policy

Not the answer you're looking for? Browse other questions tagged or ask your own question.