0

My question is very similar to Vertical alignmnent in tabularx X column type and there seems to be many similar questions so hopefully I haven't missed the answer somewhere.

However, I would like to create a new column that is a copy of tabularx X column, with the difference being the new column Y is an m column compared to a p column (which X is by default as described in the docs).

\tabularxcolumn - The default denition of X is p{#1}.

\def\tabularxcolumn#1{p{#1}}

So I would like to define a new column type like

\newcolumntype{Y}{>{\centering\arraybackslash}X}

and then convert the Y column type to m instead of p as it would currently be. That way I can leave X as it's original definition. If I use

\renewcommand{\tabularxcolumn}[1]{>{\small}m{#1}}

Then X is changed to an m column which is not desired. I would need something like

\renewcommand{Y}[1]{>{\small}m{#1}}

But that doesn't work.

Thanks for any help,

David Carlisle
  • 757,742
Prevost
  • 345

1 Answers1

1

you need to patch in a second X-like columntype, this just duplicates the definition of X so you can separately specify \tabularxcolumn for X and \tabularxycolumn for Y

enter image description here

\documentclass[a4paper]{article}
\addtolength\textwidth{5cm}
\addtolength\oddsidemargin{-3cm}
\usepackage{etoolbox,tabularx}
\tracingtabularx
\makeatletter
\newcolumntype{Y}{}
\def\tabularxycolumn#1{m{#1}}
\def\TX@newycol{\newcol@{Y}[0]}
\patchcmd\TX@endtabularx
  {\expandafter\TX@newcol}%
  {\expandafter\TX@newycol\expandafter{\tabularxycolumn{\TX@col@width}}%
   \expandafter\TX@newcol}
  {}
  {}
\patchcmd\TX@endtabularx
  {\def\NC@rewrite@X}%
  {\def\NC@rewrite@Y{\NC@rewrite@X}%
   \def\NC@rewrite@X}
  {}
  {}
\makeatother
\begin{document}


\begin{tabularx}{6cm}{XXc}
aa aaa aaa aaa aaa aaa&
bb bb bb bb bb bb bb bb bb bb bb bb bb bb b &
aa aaa
\end{tabularx}
\begin{tabularx}{6cm}{XYc}
aa aaa aaa aaa aaa aaa&
bb bb bb bb bb bb bb bb bb bb bb bb bb bb b &
aa aaa
\end{tabularx}
\begin{tabularx}{6cm}{YYc}
aa aaa aaa aaa aaa aaa&
bb bb bb bb bb bb bb bb bb bb bb bb bb bb b &
aa aaa
\end{tabularx}
\end{document}
David Carlisle
  • 757,742
  • I thought it worked but I was looking at the PDF (which compiled fine) but there were errors. I am using > pdfLaTeX Version 3.14159265-2.6-1.40.18 (MiKTeX 2.9.6500 64-bit). My original use was in knitr, but it failed there, and then I went to TexStudio, but it failed there as well. I started with a blank tex document and copied and pasted your code. Any thoughts? Thanks! – Prevost Oct 19 '18 at 23:02
  • @Prevost sorry I had omitted another place to patch in the Y version of X columns, the original wasn't counting Y columns in its count of the number of active X columns. code and result image updated – David Carlisle Oct 20 '18 at 00:02
  • That's great compiles no errors! Could that code be theoretically created from just your docs? – Prevost Oct 20 '18 at 00:19
  • @Prevost not from the user level documentation, it's definitely an extension of the design not just "using tabularx". Perhaps it could be derived from the documented code, although actually I only looked at the docstripped code with comments removed, perhaps that's why I missed one place the first time:-) – David Carlisle Oct 20 '18 at 08:12