2

I have some problems using tabular environment mixed with math formulars, multiple lines and alignment. I have this code:

\begin{tabular}[!ht]{p{5cm}p{5cm}p{5cm}}
    \toprule
    Col1 & Col2 & Col3 \\
    \midrule
        Text with a\\
        linebreak
        &
        \[
            A = B
            = C
        \]
        & Text with wrong vertical alignment \\
    \bottomrule
\end{tabular}

Which produces this latex

rendered table with math environment and wrong alignment

As you can see, there are several problems with this:

  • Col2 and A = B = C is not aligned horizontal
  • A = B = C is not at the top of the cell
  • = C should be in the next line (I need multiline equations)
  • I can't use &= C to align the equal signs when using multiline equations
  • "Text with wrong..." is also not at the top of the cell
  • I have to specify every single column with its width in cm. Is there a way to only specify one width and let the other columns fit into the left space?
  • I have to repeat the \[ and \] for every line. I found sth with predefined commands inside the {p{5cm}p{5cm}p{5cm}}, where you can add automatically a math env to the cell. But it hasn't worked

I found several table environments, like threeparttable, table, tabular... I'm a little bit confused which one to use, and I don't know how to achieve the layout I want to have (and I don't know which packages to use). So maybe someone can help me.

Kind regards.

2

you didn't provide a minimal working example (MWE) so i made some (not entirely correct) assumptions.

first, the \\ before "linebreak" causes the current line to end. use \newline instead within a paragraph in a table.

second, the amsmath aligned environment doesn't need to be in a display environment (which will center it). it works just as well within ordinary math mode. but since \\ is required for the line break, the whole thing needs to be hidden in a group, most easily done with {...} braces. and adding a [t] option will align it on the top baseline.

enter image description here

\documentclass{article}
\usepackage{amsmath}
\usepackage{booktabs}

\begin{document}
\begin{tabular}[!ht]{p{3cm}p{3cm}p{3cm}}
    \toprule
    Col1 & Col2 & Col3 \\
    \midrule
        Text with a\newline
        linebreak
        &
        {$\begin{aligned}[t]
            A &= B\\a
              &= C
          \end{aligned}
        $}
        & Text with wrong vertical alignment \\
    \bottomrule
\end{tabular}
\end{document}

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.