1

This question is a follow up to my previous question:

Is it possible to use > and < to pipe opening and closing braces on each side of a cell's content? To be more specific, what I want is to define the following column:

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

I want a column type that automatically embraces the cell content in a \parbox.

I enclose a short 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}
4
  • 1
    X column type is based on ˙\parboxes. Why you like to add them again? If you have some reason to do this, it might be better to use \minipage` (on left side) \endminipge (on the right side of column type)
    – Zarko
    Aug 18, 2019 at 15:31
  • In case you really have to split unbalanced braces across the format specifiers, the different brace tricks from The TeXbook apply
    – siracusa
    Aug 18, 2019 at 15:38
  • @Zarko Because I want to kern all the line in the cell and then I have to embrace the content in a parbox (see Bernard's answer to the referred question). minipage add top spacing, which then needs to be cancelled and complicated the column definition even more. After posting the question, I remembered the package collcell, which probably will do want I want.
    – Sveinung
    Aug 18, 2019 at 15:38
  • @siracusa Thank you for making me aware of this. I search extensively on SE, but this question did not show up. Unfortunately, this seems to be above my competence, but I will study it.
    – Sveinung
    Aug 18, 2019 at 15:41

1 Answer 1

3

Spanning the braces over >{} and <{} seems harder than expected; I can't come up with a way that uses explicit brace tokens. Here is an alternative solution that uses TeX's delimited arguments. Instead of using the \parbox directly, we define a helper macro \parboxx ... \endparboxx that wraps it. This macro is then used in the new column type 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}

outputs

enter image description here

1
  • Thank you! This seems to be a possible solution.
    – Sveinung
    Aug 18, 2019 at 17:33

You must log in to answer this question.

Not the answer you're looking for? Browse other questions tagged .