简体   繁体   中英

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?

通常,您使用p{3cm}类的列定义而不是l ,然后在单元格主体中使用\\newline而不是\\\\

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:

在此处输入图片说明

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}

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.

\\newline 用于在 tabularx 环境中的单元格内换行。

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: 在此处输入图片说明

The technical post webpages of this site follow the CC BY-SA 4.0 protocol. If you need to reprint, please indicate the site URL or the original address.Any question please contact:yoyou2525@163.com.

 
粤ICP备18138465号  © 2020-2024 STACKOOM.COM