異なる配置の複数列テーブル

異なる配置の複数列テーブル

次の複数列の表を LaTeX で描画します。見出しは中央揃え、その他のテキストは左揃えです。どうすればよいでしょうか。ここでは、One、Two などのすべてのフィールドに任意の量のテキストを含めることができます。

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

私の現在の試みは以下の通りです。さらに、次のことをしたいと考えています。

(a) 2 と 3 は、列 1 のテキストを基準に真ん中で分割されます。

(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 を分ける水平線が自動的にバランスをとらないことです。セル 2 と 4 の内容によっては、\phantom以下のコードに示すように、指示が必要になる場合があります。

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

\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

私はこれをやろうとしたstables – 簡略化されたプレーン TEX テーブル通常、各セルの中央にテキストを配置します。行の水平サイズを制御し、各セルのテキストの水平方向と垂直方向の配置を制御する方法を提供するために、各行に 1 つずつ、合計 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}

タブ付きtbl

関連情報