0

I received great help on this question: Table nesting with columnar widths based on uniform parent width, not uniform child width

I'm looking to center columns on a character in mathmode. I understand this is often conventionally done on equals or decimal points

I have a newcolumntype defined like so:

\newcolumntype{C}[1]{>{\centering\arraybackslash\hsize=#1\hsize}X}

How would I modify this column type so that the contents of the column would center on $=$ or $\rightarrow$? To somehow incorporate something like c@{$\rightarrow$}?

I tried this:

\newcolumntype{C2}[1]{>{\centering\arraybackslash\hsize=#1\hsize}X@{$\rightarrow$}}

But the result when I used it was

! Package array Error:  Illegal pream-token (2.3333): `c' used.
Mittenchops
  • 1,044
  • 1
    Replace \newcolumntype{C2} by \newcolumntype{A} (or any other letter except c, l, r, m, p, b, X and S) – leandriis Nov 08 '18 at 21:47

1 Answers1

4

You can use the dcolumn package and a column such as D{>}{\rightarrow}{-1}

enter image description here

\documentclass{article}

\usepackage{dcolumn,tabularx}

\newcolumntype{C}{D>{\;\rightarrow\;}{3.3}}

\begin{document}

\begin{tabularx}{.5\textwidth}{XCX}
  xxx & 1 > 2 & hh\\
  x & 1 > 222 & hhhh\\
  xxx & 123 > 2 & hh\\
\end{tabularx}
\end{document}
David Carlisle
  • 757,742
  • Does dcolumn work with tabularx? I'm getting:
    <inserted text> 
                    $
    l.814 \end{tabularx}
    
    – Mittenchops Nov 08 '18 at 22:13
  • This doesn't seem to work for me: `! Improper alphabetic constant. \rightarrow ` – Mittenchops Nov 08 '18 at 22:40
  • @Mittenchops the code posted should work (there was an initial version before an edit that had \rightarrow in two places, the character in the data needs to be a character not a command so I use > here to represent the arrow,. Works with tabularx, I will use tabularx instead of tabular in the example, look in a minute – David Carlisle Nov 09 '18 at 00:14