LaTeXで行の長さが異なる特別なテーブルを作成する

LaTeXで行の長さが異なる特別なテーブルを作成する

次の図のような表を LaTeX で作成するにはどうすればよいでしょうか? ここに画像の説明を入力してください

答え1

可能な解決策。私が提案するのは縦線を使わないではなく、booktabsパッケージ。水平方向の20配置には、multirowパッケージでは、垂直方向の配置については、最初の列の最大エントリの幅を次のように計算できます。calcパッケージ。

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

\documentclass{article}
\usepackage{booktabs,calc,multirow}

\newlength\wdx% for vertical alignment
\setlength{\wdx}{\widthof{66}}

\begin{document}

\begin{table}
\centering
\addtolength{\tabcolsep}{10pt}% increase distance between cells 
\begin{tabular}{cccccc}
\toprule
\textsf{x} & \multicolumn{5}{c}{\textsf{y}}\\
\cmidrule(l{\wdx}r{\wdx}){1-1}\cmidrule(l){2-6}
10 & 22 & 33 \\
\multirow{2}[2]{\wdx}{20} & 45 & 34 & 88 & 77 & 80 \\
 & 34 & 67\\
66 & 12 & 10 & 45 & 66\\ 
\bottomrule
\end{tabular}
\end{table}

\end{document}

答え2

表に縦罫線を使用する必要がある場合は、 で描かれた水平線の上下の縦方向の間隔を広くするために「支柱」も挿入することをお勧めします\hline。ただし、一般的には、表を作成するのが好ましいと思います。それなし垂直方向の罫線と、、などで描かれた間隔の広い水平線を取得するためにパッケージを使用しますbooktabs\toprule\midrule

最初の列の 2 番目のエントリを垂直方向に中央揃えするには、\multirow命令を使用します。

最初の列を常に太字にする作業を自動化することもできます。

最後に、パッケージを使用する場合tabularx、たとえば、テーブルの幅を事前に指定し、コンテンツを中央揃えにしたい場合 (投稿したスクリーンショットではそうであるようです)、パッケージXによって提供される列タイプの特別な「中央揃え」バージョンも定義する必要がありますtabularx

以下の最初の表はtabular環境を使用し、2 番目の表はtabularx合計幅が に設定された 環境を使用しています0.7\textwidth。2 番目の表も sans-serif に設定されています。

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

\documentclass[10pt,a4paper]{article}
\usepackage{multirow,array}
% define "struts" as suggested by Claudio Beccari in
%    a piece in TeX and TUG News, Vol. 2, 1993.
\newcommand\T{\rule{0pt}{2.6ex}}       % = `top' strut
\newcommand\B{\rule[-0.9ex]{0pt}{0pt}} % = `bottom' strut
\newcommand\TB{\T\B} % top-and-bottom strut 

\usepackage{tabularx}
\newcolumntype{C}{>{\centering\arraybackslash}X}
\begin{document}

\begin{tabular}{>{\bfseries}c|ccccc}
x & \multicolumn{5}{c}{\bfseries y\B}\\
\hline
10 & 22 & 33\TB\\
\hline
\multirow{2}{*}{20} & 45 & 34 & 88 & 77 & 80\T\\
 & 34 & 67\B \\
\hline
66 & 12 & 10 & 45 & 66\T\\
\end{tabular}

\bigskip

\textsf{ % switch to sans-serif for the second table
\begin{tabularx}{0.7\textwidth}{>{\bfseries}C|CCCCC}
x & \multicolumn{5}{c}{\bfseries y\B}\\
\hline
10 & 22 & 33\TB\\
\hline
\multirow{2}{*}{20} & 45 & 34 & 88 & 77 & 80\T\\
 & 34 & 67\B \\
\hline
66 & 12 & 10 & 45 & 66\T\\
\end{tabularx}}
\end{document}

答え3

arrayに加えて、パッケージのみを使用するソリューションmakecell。利点の1つは、コマンドを使用すると、はるかにタイトな行を少なくできることです\makecell*(これにより、\jot 対称的にとは異なり、セルの上部と下部に が表示されます\renewcommand{\arraystretch}{…}。もう 1 つは、hlines の太さを変更できることです ( と同様ですbooktabsが、垂直線を使用する可能性は保持されます)。

    \documentclass{article}

    \usepackage[utf8]{inputenc}
    \usepackage{array, makecell}

    \begin{document}

    \begin{table}
    \centering\sffamily
    \addtolength{\tabcolsep}{10pt}% increase distance between cells
    \begin{tabular}{c!{\vline width1pt}*{5}{c}}
    \makecell*{x} & \multicolumn{5}{c}{y}\\
    \Xhline{1pt}
    \makecell*{10} & 22 & 33 \\
    \hline
    \makecell{20\\[-2.5ex]}& \makecell*[tc]{45\\34} & \makecell[tc]{34\\67} & 88 & 77 & 80 \\
    \hline
    \makecell*{66} & 12 & 10 & 45 & 66
    \end{tabular}
    \end{table}

    \end{document} 

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

関連情報