1

I have a table like in the following example:

\documentclass[11p,twoside,a4paper,leqno]{article}
\usepackage[utf8]{inputenc}
\usepackage{mathtools}
\usepackage{amsfonts}
\usepackage{xcolor}
\usepackage{array}

\begin{document}
\begin{tabular}{|l|c|}
    text & text \\
    text & \(math1\) \(math2\)
\end{tabular}
\end{document}

I need to insert a line break between math1 and math2 while still keeping the text centered. How do I do this?

EDIT: Changed code to a minimal working example

1

4 Answers 4

3

The stackengine package can help. If you would prefer constant inter-baseline skip, rather than fixed inter-item gap, you can add these lines to the preamble:

\def\stacktype{L}
\setstackgap{L}{12pt}

If you would like the math itself left or right aligned (while still retaining the center alignment of the column), add \def\stackalignment{l} or \def\stackalignment{r} to your preamble.

If you wish to stack text rather than math, by default, remove the \stackMath line from the preamble.

Here is the MWE

\documentclass[11p,twoside,a4paper,leqno]{article}
\usepackage[utf8]{inputenc}
\usepackage{mathtools}
\usepackage{amsfonts}
\usepackage{xcolor}
\usepackage{array}
\usepackage{stackengine}
\stackMath
\begin{document}
\parskip 1em
\renewcommand\arraystretch{1.5}
\begin{tabular}{|l|c|}
    text & text \\
    stackon & \stackon{a_1 x + b_1 y = c_1}{a_2 x  = c_2}\\
\end{tabular}

\begin{tabular}{|l|c|}
    text & text \\
    stackunder & \stackunder{a_1 x + b_1 y = c_1}{a_2 x +b_2 y = c_2}\\
\end{tabular}

\begin{tabular}{|l|c|}
    text & text \\
    stackanchor & \stackanchor{a_1 x + b_1 y = c_1}{a_2 x  = c_2}\\
\end{tabular}
\end{document}

enter image description here

If one needs to do aligned math in the tabular, then the tabstackengine package extends the stackengine approach. However, because it is inside a tabular, the default tab character and end-of-line character need to be changed to avoid conflict.

\documentclass[11p,twoside,a4paper,leqno]{article}
\usepackage[utf8]{inputenc}
\usepackage{mathtools}
\usepackage{amsfonts}
\usepackage{xcolor}
\usepackage{array}
\usepackage{tabstackengine}
\setstackTAB{\&}
\setstackEOL{\#}
\setstackgap{L}{12pt}
\stackMath
\setstacktabulargap{0pt}
\TABbinary
\begin{document}
\parskip 1em
\renewcommand\arraystretch{1.5}
\begin{tabular}{|l|c|}
    text & text \\
    tabularCenterstack & 
    \tabularCenterstack{rrl}{%
a_1 x \&+ b_1 y =\& c_1\#
a_2 x \& =\& c_2\#
\&b_3 y  =\& c_3 + d_3}\\
\end{tabular}

\begin{tabular}{|l|c|}
    text & text \\
    alignCenterstack & 
    \alignCenterstack{%
z \&=a_1 x + b_1 y \#
w + z \&= a_2 x  \#
v + w \&=a_3 x - b_3 y}\\
\end{tabular}
\end{document}

enter image description here

0
2

Use a nested tabular

\documentclass{article}
\usepackage{mathtools}
\usepackage{array}
\newcommand{\mycell}[2][c]{%
  \begin{tabular}[#1]{@{}c@{}}
    #2
  \end{tabular}
  }
\begin{document}
\begin{tabular}{|l|c|}
    text & text \\
    text & \mycell{$a_1 x + b_1 y = c_1$ \\ $a_2 x  = c_2$}\\
\end{tabular}

\bigskip
\begin{tabular}{|l|c|}
    text & text \\
    text & \mycell[t]{$a_1 x + b_1 y = c_1$ \\ $a_2 x  = c_2$}\\
\end{tabular}

\bigskip
\begin{tabular}{|l|c|}
    text & text \\
    text & \mycell[b]{$a_1 x + b_1 y = c_1$ \\ $a_2 x  = c_2$}\\
\end{tabular}

\end{document}

enter image description here

2

The makecell package is done for that. It also allows for a common formatting of cells, and it also has a multirowcell command:

\documentclass[11p,twoside,a4paper,leqno]{article}
\usepackage[utf8]{inputenc}
\usepackage{mathtools}
\usepackage{amsfonts}
\usepackage{xcolor}
\usepackage{array, makecell}

\begin{document}
  \begin{tabular}{|l|c|}
    text & text \\
    text & \makecell{\(a < b\)\\ \(a + c < b + c\)}
\end{tabular}
\end{document} 

enter image description here

0

You can use multirowpackage.

\documentclass[11p,twoside,a4paper,leqno]{article}
\usepackage[utf8]{inputenc}
\usepackage{mathtools}
\usepackage{amsfonts}
\usepackage{xcolor}
\usepackage{array}
\usepackage{multirow}
\begin{document}


\begin{table}[h]
\begin{tabular}{|l|c|}
\hline
text                  & text                      \\ \hline
\multirow{2}{*}{text} & \(\cos (2\theta) = \cos^2 \theta - \sin^2 \theta\)                        \\
                  & \multicolumn{1}{l|}{\(\sqrt[n]{1+x+x^2+x^3+\ldots}\)} \\ \hline
\end{tabular}
\end{table}
\end{document}

Result is

Table with a line break

For table generation you can check Tables Generator it makes tables easier for a beginner.

You must log in to answer this question.