この特定の表のコードを Latex で記述したいと考えました (上の画像)。表の境界線の幅、表の境界線の色、および 2 つのセル間の空白を定義したいと考えました。また、テキストを水平方向と垂直方向に中央揃えにしたいと考えました。
私は次のようなことを試しました:
\documentclass{article}
\usepackage[table]{xcolor}
\usepackage{tabularx, graphicx}
\definecolor{green}{RGB}{0,255,0}
\definecolor{blue}{RGB}{0,0,255}
\begin{document}
\setlength{\arrayrulewidth}{1mm}
\renewcommand{\arraystretch}{2}
\noindent
\begin{table}[h!]
\centering
\begin{tabular}{cc}
\arrayrulecolor{green}
\begin{tabular}{|>{\centering\arraybackslash}m{5cm}|}
\hline
\color{green} GREEN \\
\hline
\end{tabular}
&
\arrayrulecolor{blue}
\begin{tabular}{|>{\centering\arraybackslash}m{5cm}|}
\hline
\color{blue} BLUE \\
\hline
\end{tabular}
\end{tabular}
\end{table}
\end{document}
コードを編集し、動作はしますが、抑制できない警告が表示されます: 「\hline コマンドを間違った場所 (おそらくテーブルの外部) で使用しました。\hline コマンドがテーブル内に記述されている場合は、その前に \ を含めてみてください。」
テーブル内の境界線の色を変更できないようです。
答え1
これには必ずしもテーブルは必要ありません。 2 つのボックスを、サイズに応じた空白を空けて水平に並べることもできます。
\documentclass{article}
\usepackage[svgnames]{xcolor}
\begin{document}
{%
\centering
\setlength\fboxrule{1mm} % Line width
\setlength\fboxsep{6pt} % Padding
\fcolorbox{Green}{Green!5}{% or white instead of the tint Green!5
\parbox{4cm}{\centering\textcolor{Green}{GREEN}}}%
\hspace{2em}%A
\fcolorbox{Blue}{Blue!5}{%
\parbox{4cm}{\centering\textcolor{Blue}{BLUE}}}
\par}
\end{document}
あるいは、ティックズ角を丸くするなど、いくつかのオプションが追加されました。ただし、 を学習する必要があります。tikz
これは、追加モジュールを含む巨大なパッケージであり、最初は少し怖いかもしれません。
\documentclass{article}
\usepackage[svgnames]{xcolor}
\usepackage{tikz}
\usetikzlibrary{positioning}
\newcommand\boxtext{Sample sample sample sample sample sample sample}
\tikzset{
box/.style = {
draw,
line width = 1mm,
color=#1, fill=#1!5,
align=center, text width=4cm, font=\normalfont,
inner sep=6pt+1mm, outer sep=0pt,
rounded corners,
},
}
\begin{document}
{%
\centering
\tikz[node distance = 2em] {
\node (G) [box=Green] {\boxtext};
\node (B) [box=Blue, right=of G] {\boxtext};}
\par}
\end{document}
答え2
回避策として、メインの表形式の 2 番目のセルにある小さな表形式に{NiceTabular}
of を使用できますnicematrix
。環境には、{NiceTabular}
ルールの色用の独自のキーがあります。
\documentclass{article}
\usepackage[table]{xcolor}
\usepackage{tabularx, graphicx}
\usepackage{nicematrix}
\definecolor{green}{RGB}{0,255,0}
\definecolor{blue}{RGB}{0,0,255}
\begin{document}
\setlength{\arrayrulewidth}{1mm}
\renewcommand{\arraystretch}{2}
\noindent
\begin{table}[h!]
\centering
\begin{tabular}{cc}
\arrayrulecolor{green}
\begin{tabular}{|>{\centering\arraybackslash}m{5cm}|}
\hline
\color{green} GREEN \\
\hline
\end{tabular}
&
\begin{NiceTabular}{|>{\centering\arraybackslash}m{5cm}|}[rules/color=blue]
\hline
\color{blue} BLUE \\
\hline
\end{NiceTabular}
\end{tabular}
\end{table}
\end{document}
複数のコンパイルが必要です (nicematrix
内部で PGF/Tikz ノードが使用されるため)。
答え3
以下は、hhline と colortbl を使用した私の解決策です。
\documentclass{article}
\usepackage{hhline,colortbl}
%New column type so that text is centered
\newcolumntype{M}[1]{>{\centering\arraybackslash}m{#1}}
%Custom colors if needed
\definecolor{green}{RGB}{0,255,0}
\definecolor{blue}{RGB}{0,0,255}
\begin{document}
\setlength\arrayrulewidth{2pt} % thickness of table lines
\renewcommand{\arraystretch}{2} % horizontal spacing
%create a new hline called myhline with the colors needed
\newcommand\myhline[1]{%
\hhline{%
>{\arrayrulecolor {green}}%
#1|-% solid green colored line
>{}%
#1|~% no line
>{\arrayrulecolor{blue}}%
|-#1% solid blue colored line
}}
% start array
\begin{tabular}{
!{\color{green}\vrule width 2pt } % vertical line color, line width
M{5cm} % custom column type, column width
!{\color{green}\vrule width 2pt}
M{1cm}
!{\color{blue}\vrule width 2pt}
M{5cm}
!{\color{blue}\vrule width 2pt}
}
\myhline{}% Draw custom line
\color{green} GREEN& &\color{blue} BLUE\\
\myhline{}% Draw custom line
\end{tabular}
\end{document}
参考文献:
答え4
解決tabularray
策が見つかりません:
\documentclass{article}
\usepackage{xcolor}
\usepackage{tabularray}
\begin{document}
\begin{table}[h!]
\centering
\begin{tblr}{colspec={Q[c,m,5cm, fg=green]cQ[c,m,5cm, fg=blue]},
hline{1-2}={1}{green, wd=1mm},
vline{1-2}={green, wd=1mm},
hline{1-2}={3}{blue, wd=1mm},
vline{3-4}={blue, wd=1mm},
rows={ht=1cm},stretch=0
}
GREEN && BLUE \\
\end{tblr}
\end{table}
\end{document}