各ボックスに複数の行がある表を作成する

各ボックスに複数の行がある表を作成する

各ボックスに複数のテキスト行が重なって表示される大きな表を作成しようとしています。新しい行に移動しよう\newlineとしました\linebreakが、どちらも機能しません。コマンドは\\新しい行を作成しますが、表全体の行全体が終了してしまいます。

新しい回線、あるいはもっと良いパッケージを入手する方法を提案してくれる人はいませんか?

答え1

次のように使用しますparbox{}{}

\documentclass{standalone}

\begin{document}

    \begin{tabular}{ll}
        \hline
        row 1, column 1, line 1 & \parbox{5cm}{row 1, column 2, line 1 \\ row 1, column 2, line 2 \\ row 1, column 2, line 3} \\ \hline
        \parbox{5cm}{row 2, column 1, line 1 \\ row 2, column 1, line 2} & row 2, column 2, line 1 \\ 
        \hline
    \end{tabular}

\end{document}

ここに画像の説明を入力してください

答え2

解決方法はいくつか考えられます。以下は 2 つのアプローチを示しています。1 つ目は標準コマンドのみを使用する方法です。見た目の理由から を使用しましたがbooktabs、これはソリューションに必須ではありません。2 つ目は を使用しますtabularx

表形式で <code>\newline</code> を取得する 2 つの方法

\documentclass{article}
\usepackage{tabularx,booktabs}
\begin{document}

One method involves using the standard \verb|p{<width>}| column specifier. This requires knowing how wide you want the columns but it allows you to use \verb|\newline| and does not require additional packages. Table \ref{tab:standard} does use commands from \verb|booktabs| to improve the tabular's appearance but you could replace with \verb|\hline| etc.\ if preferred.
\begin{table}
\centering
\begin{tabular}{*{2}{p{.285\linewidth}}}
    \toprule
    row 1, column 1, line 1 & row 1, column 2, line 1\newline row 1, column 2, line 2\newline row 1, column 2, line 3\\\midrule
    row 2, column 1, line 1\newline row 2, column 1, line 2 & row 2, column 2, line 1 \\
    \bottomrule
\end{tabular}
\caption{Tabular with standard commands}\label{tab:standard}
\end{table}
\bigskip

If you don't know how wide the columns should be and don't wish to figure it out, but you can specify the overall width of the tabular, \verb|tabularx| can be used. This supports the \verb|X| column specifier which figures out the width based on the overall tabular width. It also allows \verb|\newline|. Table \ref{tab:tabularx} again uses \verb|booktabs| but that is for merely aesthetic reasons.
\begin{table}
\centering
\begin{tabularx}{.65\linewidth}{XX}
    \toprule
    row 1, column 1, line 1 & row 1, column 2, line 1\newline row 1, column 2, line 2\newline row 1, column 2, line 3\\\midrule
    row 2, column 1, line 1\newline row 2, column 1, line 2 & row 2, column 2, line 1 \\
    \bottomrule
\end{tabularx}
\caption{Tabular with tabularx}\label{tab:tabularx}
\end{table}

\end{document}

答え3

前のリンクでは言及されていませんが、パッケージは、の使用を受け入れ、さらにカスタマイズできる (フォントの選択、回転、垂直スペースなど) 、、およびコマンドを定義makecellします。hlines と clines の太さを変更できます。\makecelltheaddiaghead\multirowcell\\

見るこのスレッド使用例を知るため。

関連情報