不均衡な中括弧 (`{` と `}`) を表形式の列にリダイレクトすることは可能ですか?

不均衡な中括弧 (`{` と `}`) を表形式の列にリダイレクトすることは可能ですか?

この質問は私の前の質問:

>セルの内容の両側に開き中括弧と閉じ中括弧をパイプして使用することは可能ですか<? 具体的には、次の列を定義したいのです。

\newcolumntype{P}{>{\leavevmode\kern-\tabcolsep\bfseries\parbox[t]{\hsize}{}X<{}}}

セルの内容を自動的に取り込む列タイプが必要です\parbox

短い MNWE を同封します:

\documentclass[table]{article}
\usepackage{lmodern, microtype, xcolor, tabularx, tabulary}

\begin{document}

\begin{tabularx}{0.5\columnwidth}{>{\raggedright\arraybackslash\leavevmode\kern-\tabcolsep\parbox[t]{\hsize}{ }X<{}}XX<{\leavevmode\kern-\tabcolsep\raggedleft\arraybackslash}}

\rowcolor{lightgray}All this testing is not so funny&test&test\\\hline
testing, testing and even more testing &test&test\\
\rowcolor{lightgray}I want to write a noce table in a simple way&test&test\\
\end{tabularx}

\end{document}

答え1

中括弧を と にまたがって記述するの>{}<{}予想以上に難しいようです。明示的な中括弧トークンを使用する方法が思いつきません。TeX の区切り引数を使用する代替ソリューションを次に示します。 を\parbox直接使用する代わりに、それをラップするヘルパー マクロを定義します\parboxx ... \endparboxx。このマクロは、新しい列タイプ で使用されますP

\documentclass[table]{article}
\usepackage{lmodern, microtype, xcolor, tabularx, tabulary}

\begin{document}

\def\parboxx#1\endparboxx{\parbox[t]{\hsize}{\raggedright#1}}

\newcolumntype{P}{>{\leavevmode\kern-\tabcolsep\bfseries\parboxx}X<{\endparboxx}}

\begin{tabularx}{0.5\columnwidth}{PXX<{\leavevmode\kern-\tabcolsep\raggedleft\arraybackslash}}

\rowcolor{lightgray}All this testing is not so funny&test&test\\\hline
testing, testing and even more testing &test&test\\
\rowcolor{lightgray}I want to write a noce table in a simple way&test&test\\
\end{tabularx}

\end{document}

出力

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

関連情報