각 상자에 여러 줄이 포함된 표 만들기

각 상자에 여러 줄이 포함된 표 만들기

저는 각 상자 아래에 여러 줄의 텍스트가 있는 큰 테이블을 만들려고 합니다. 나는 새로운 라인에 들어가려고 노력했지만 둘 다 작동하지 \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가지 접근 방식을 보여줍니다. 첫 번째는 표준 명령에만 의존합니다. 미적인 이유로 사용했지만 booktabs이것이 솔루션에 필수적인 것은 아닙니다. 두 번째는 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\\

보다이 스레드사용 예를 들어보겠습니다.

관련 정보