How to code tables with multi-line cells

前端 未结 4 1653
萌比男神i
萌比男神i 2021-01-30 10:25

I am trying to write a short paper with LaTeX and need to add a table with 3 columns.

+-------------+-----------------+--------------------------------------+
|          


        
4条回答
  •  孤独总比滥情好
    2021-01-30 11:04

    This is the answer I found so far for my needs: Link here.

    It creates a new command that will make a table inside a table in a more proper way:

    \newcommand{\specialcell}[2][c]{%
    \begin{tabular}[#1]{@{}c@{}}#2\end{tabular}}
    

    So, if want to do a forced line break inside a cell like here:

    \begin{tabular}{|c|c|c|}
    \hline
    Foo bar & Foo  bar & Foo bar \\
    \hline
    \end{tabular}
    

    You will end up using a code like this:

    Foo bar & \specialcell{Foo\\bar} & Foo bar \\    % vertically centered
    Foo bar & \specialcell[t]{Foo\\bar} & Foo bar \\ % aligned with top rule
    Foo bar & \specialcell[b]{Foo\\bar} & Foo bar \\ % aligned with bottom rule
    

    Horizontal alignment can be controlled in the declaration of the new command by changing c@ to l@ or r@

    All credit goes to egreg from the Tex forum. Do upvote his answer !

提交回复
热议问题