정렬이 다른 다중 열 테이블

정렬이 다른 다중 열 테이블

라텍스로 다음과 같은 다중 열 테이블을 그리고 싶습니다. 제목은 중앙에 정렬되고 다른 텍스트는 왼쪽에 정렬됩니다. 어떻게 해야 하나요? 여기에서는 One, Two 등과 같은 모든 필드에 임의의 양의 텍스트가 포함될 수 있습니다.

여기에 이미지 설명을 입력하세요

현재 시도는 다음과 같습니다. 나는 또한 다음을 갖고 싶다:

(a) 1열의 텍스트와 관련하여 2와 3이 중간에 분할되었습니다.

(b) 제목을 제외한 모든 텍스트는 왼쪽 정렬됩니다.

(c) 2와 3 사이의 직선

\documentclass{article}
\usepackage{blindtext}
\begin{document}
\begin{tabular}{|p{5cm}|c|c|c|}
\hline
\textbf{A} & \textbf{B} & \textbf{C} & \textbf{D}\\
\hline
\blindtext & \begin{tabular}{@{}c@{}}Two \\ Three\end{tabular} & Four & Six
\end{tabular}
\end{document}

답변1

\documentclass{article}
\usepackage{multirow}
\usepackage{multicol}
\usepackage{blindtext}
\begin{document}
\begin{tabular}{|p{5cm}|l|l|l|}
\hline
\multicolumn{1}{|c}{\textbf{A} }& \multicolumn{1}{|c|}{\textbf{B} }& \multicolumn{1}{c}{\textbf{C} }& \multicolumn{1}{|c|}{\textbf{D} }\\
\hline
\multirow{2}{*}{One} & Two  & Four & \multirow{2}{*}{Six}  \\ \cline{2-3}
 &  Three & Five & \\ \hline
Seven& Eight & Nine & Ten \\ \hline
\end{tabular}
\end{document}

여기에 이미지 설명을 입력하세요

답변2

귀하의 요구 사항을 다음과 같이 해석합니다. (a) 열 "A"는 열 "B" 너비의 절반이어야 하며 함께 사용 가능한 너비의 전반부에 걸쳐 있어야 합니다. (b) "C" 열과 "D" 열은 너비가 동일해야 하며 후반부에 걸쳐 있어야 합니다. (c) 모든 셀의 내용은 위쪽에 정렬되어야 합니다. (d) 셀의 중간 행의 높이는 "1"과 "6" 셀 중 더 큰 셀에 의해 결정됩니다.

이 해석이 정확하다면 다음 설정이 원하는 것일 수 있습니다. 내 생각에 유일한 단점은 셀 2/4와 셀 3/5를 구분하는 수평선이 자동으로 균형을 이루지 않는다는 것입니다. \phantom아래 코드에서 볼 수 있듯이 셀 2와 4의 내용에 따라 명령이 필요할 수 있습니다.

여기에 이미지 설명을 입력하세요

\documentclass{article}
\usepackage{array,ragged2e}
\newcolumntype{P}[1]{>{\RaggedRight\arraybackslash}p{#1}}

\newlength\tablengtho
\newlength\tablengtha
\newlength\tablengthb
\newlength\tablengthcd

% Calculare widths of columns A, B, and C/D
\setlength\tablengtho{\dimexpr\textwidth-8\tabcolsep-5\arrayrulewidth\relax}
\setlength\tablengtha{\dimexpr0.6667\tablengtho/4\relax}
\setlength\tablengthb{\dimexpr1.3333\tablengtho/4\relax}
\setlength\tablengthcd{\dimexpr\tablengtho/4\relax}

\begin{document}

\noindent
\begin{tabular}{| P{\tablengtha} | P{\tablengthb} |
                  P{\tablengthcd} | P{\tablengthcd} |}
\hline
\multicolumn{1}{|c|}{\textbf{A}} & \multicolumn{1}{c|}{\textbf{B}} &
\multicolumn{1}{c|}{\textbf{C}} & \multicolumn{1}{c|}{\textbf{D}} \\
\hline
One One One One One One One One One  & 
\multicolumn{1}{@{}c@{}|}{%
   \begin{tabular}[t]{P{\tablengthb}}
         Two Two Two Two Two Two Two   \\ 
         \hline
         Three Three Three Three Three \\
   \end{tabular}} &
\multicolumn{1}{@{}c@{}|}{%
   \begin{tabular}[t]{P{\tablengthcd}}
         Four Four Four \phantom{Four} \\ % \phantom{Four} needed for balance
         \hline
         Five Five Five \\
   \end{tabular}} &
Six Six Six Six Six Six Six Six Six Six Six Six Six Six Six Six Six Six Six Six Six \\
\hline
Seven & Eight & Nine & Ten \\
\hline
\end{tabular}

\end{document}

답변3

나는 이것을하려고 노력했다.마구간 – 단순화된 일반 TEX 테이블일반적으로 각 셀의 중앙에 텍스트를 배치합니다. 행의 가로 크기를 제어하고 각 셀의 텍스트 배치를 가로 및 세로로 제어하는 ​​방법을 제공하기 위해 각 행마다 하나씩 4개의 매크로를 사용했습니다.

\documentclass{article}

\input stables.tex

%the width of each column is controlled by the "\hsize=" in each of the four macros
%for each macro the first variable controls horizontal placement of the text, the second 
%takes the text itself and the third controls vertical placement of the text.
\def\AA#1#2#3{\hphantom{\hspace{#1}}% 
   \vtop{\hsize=1.2in\vskip#3 #2}\hphantom{\hspace{1pt}}}

\def\BB#1#2#3{\hphantom{\hspace{#1}}%
   \vtop{\hsize=2.2in\vskip#3 #2}\hphantom{\hspace{1pt}}}

\def\CC#1#2#3{\hphantom{\hspace{#1}}%
   \vtop{\hsize=1in\vskip#3 #2}\hphantom{\hspace{1pt}}}

\def\DD#1#2#3{\hphantom{\hspace{#1}}%
   \vtop{\hsize=1.4in\vskip#3 #2}\hphantom{\hspace{1pt}}}

\begin{document}

\begintable

A|B|C|D\elt
\multirow4{\AA{-.1cm}{One}{-.9cm}}|\BB{-.6cm}{Two}{-.2cm} |\CC{-.8cm}%
{Four}{-.2cm}|\multirow4{\DD{-.1cm}{Six}{-.9cm}}\elspec
|||\el
|||\el
|\trule|\trule| \el
|\BB{-.6cm}{Three}{-.4cm} |\CC{-.8cm}{Five}{-.4cm}|\el
|||\elt
\AA{-.9cm}{Seven}{-.2cm}|\BB{-.9cm}{Eight}{-.2cm}|\CC{-.8cm}{Nine}%  
{-.2cm}|\DD{-1cm}{Ten}{-.2cm}

\endtable

\end{document}

내 결과는 다음과 같습니다.

여기에 이미지 설명을 입력하세요

답변4

패키지 북탭을 이용하는 것이 더 좋습니다. 규칙은 행 사이에 약간의 공간을 제공합니다.

\documentclass{article}
\usepackage{booktabs}
\usepackage{multirow}
\begin{document}
\begin{tabular}{p{5cm}|l|l|l}
\toprule
\multicolumn{1}{c}{\textbf{A} }& \multicolumn{1}{|c}{\textbf{B} }& \multicolumn{1}{|c}{\textbf{C} }& \multicolumn{1}{|c}{\textbf{D} }\\
\midrule
\multirow{2}{*}{One} & Two  & Four & \multirow{2}{*}{Six}  \\ \cmidrule{2-3}
&  Three & Five & \\ \midrule
Seven& Eight & Nine & Ten \\ \bottomrule
\end{tabular}
\end{document}

tblwithtabs

관련 정보