ssn
ssn

Reputation: 2907

How to insert manual line breaks inside LaTeX tables?

I know that if you define a width in a table's column, you can get automatic word-wrapping. However, I need to control where newlines should happen in a specific table cell.

Thus, how can I insert manual line breaks in a LaTeX table cell?

Upvotes: 54

Views: 189967

Answers (6)

Luciano Dourado
Luciano Dourado

Reputation: 502

You can do like Bart suggested above and combine with multirow to centralize single line texts.

\begin{table}[h]
    \centering
    \caption{Optimized models (Softmax) final results with confidence intervals.}
        \begin{tabular}{|c|c|c|c|c|}
        \hline
         \multirow{2}*{Architecture} & Batch & N. & Learning & \multirow{2}*{Micro-F1} \\
          & size & epochs & rate &  \\
         \hline
         ResNet50& 64 & 60 & $5\times10^{-3}$ & $(\textbf{0.7683} \pm 0.0223)$ \\
         \hline
         ResNet152\_V2& 64 & 40 & $5\times10^{-4}$ & $(0.6698 \pm 0.0467)$\\
         \hline
    \end{tabular}
\label{final_result_softmax}
\end{table}

Yields: enter image description here

Upvotes: -1

user13661228
user13661228

Reputation: 13

\newline works to break a line within a cell in tabularx environment.

Upvotes: -3

PlasmaBinturong
PlasmaBinturong

Reputation: 2274

The command \shortstack can be used to wrap cell content and use \\ inside it:

\begin{tabular}{|l|l|}
\hline
one line & \shortstack{two\\ lines} \\
\hline
XX & YYY \\
\hline
\end{tabular}

EDIT: however I just realised that interline spacing might differ between your columns. So it's not the prettiest solution.

Upvotes: 15

Binita Bharati
Binita Bharati

Reputation: 5898

It can be achieved by using \newline. Since, the accepted answer did not have any sample snippet, a working sample is provided here:

 \begin{tabular}{p{2cm} p{10cm}}
    \em{Programming} \textsc{languages} & Java, Node.js, Python, Clojure \\
    \newline & \newline \\
    \em{Development systems} & Concurrent Programming, Design Patterns 
 \end{tabular}

Upvotes: 7

Bart Kiers
Bart Kiers

Reputation: 170158

You could do it like this:

\documentclass{report}

\begin{document}

\begin{tabular}{|l|l|}
  \hline
  A & B \\ 
    & C \\ 
  \hline
  D & E \\
  \hline
\end{tabular}

\end{document}

which produces:

enter image description here

Upvotes: 30

Kilian Foth
Kilian Foth

Reputation: 14346

Usually, you use a column definition like p{3cm} instead of l, and then use \newline instead of \\ in the cell body.

Upvotes: 80

Related Questions