
這個問題是我的後續問題上一個問題:
是否可以在單元格內容的每一側使用>
and管道打開和關閉大括號?<
更具體地說,我想要定義以下列:
\newcolumntype{P}{>{\leavevmode\kern-\tabcolsep\bfseries\parbox[t]{\hsize}{}X<{}}}
我想要一種能夠自動包含 .txt 檔案中的儲存格內容的欄位類型\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}
輸出