2

What is the easiest way to get that last square aligned the same was as the first two? Do I need to create a \newcolumntype that somehow centers the content both vertically and horizontally? If so, how do I do that?

\documentclass{article}

\usepackage{tikz}

\usepackage{tabularx}
\newcolumntype{C}[1]{>{\centering\arraybackslash}m{#1}}
\newcolumntype{Y}{>{\centering\arraybackslash}X}

\begin{document}

\begin{tabularx}{16cm}{C{5cm}C{5cm}Y}

\begin{tikzpicture}[scale=0.7]
\draw (0,0) rectangle (4,4);
\end{tikzpicture}

&

\begin{tikzpicture}[scale=0.7]
\draw (0,0) rectangle (4,4);
\end{tikzpicture}

&

\begin{tikzpicture}[scale=0.7]
\draw (0,0) rectangle (4,4);
\end{tikzpicture}\\

\end{tabularx}

\end{document}
4
  • That is not weird. That's what I'd expect. Presumably, you expected something else. Since you don't say what, it is hard to be more helpful.
    – cfr
    Aug 24, 2015 at 2:48
  • @cfr I agree. I just fixed the title. I just don't know how to fix the situation. Aug 24, 2015 at 3:09
  • Thanks. That's much clearer. The documentation offers \renewcommand{\tabularxcolumn}[1]{>{\centering\arraybackslash}m{#1}} to change what X does but I'm not sure you can do it for just one column.
    – cfr
    Aug 24, 2015 at 3:20
  • The solution proposed for @cfr works for me if you suppress \\ on last tabularx row.
    – Ignasi
    Aug 24, 2015 at 9:12

1 Answer 1

4

The documentation suggests changing the format of X columns with

\renewcommand{\tabularxcolumn}[1]{>{\centering\arraybackslash}m{#1}}

which seems to work here, although the result is too wide for the text block, so I added geometry and made a bit more room.

\documentclass{article}
\usepackage{tikz,geometry}
\geometry{scale=.8}
\usepackage{tabularx}
\renewcommand{\tabularxcolumn}[1]{>{\centering\arraybackslash}m{#1}}% from the documentation
\newcolumntype{C}[1]{>{\centering\arraybackslash}m{#1}}
\newcolumntype{Y}{>{\centering\arraybackslash}X}
\begin{document}
\begin{tabularx}{16cm}{C{5cm}C{5cm}Y}
  \begin{tikzpicture}[scale=0.7]
    \draw (0,0) rectangle (4,4);
  \end{tikzpicture}
  &
  \begin{tikzpicture}[scale=0.7]
    \draw (0,0) rectangle (4,4);
  \end{tikzpicture}
  &
  \begin{tikzpicture}[scale=0.7]
    \draw (0,0) rectangle (4,4);
  \end{tikzpicture}\\
\end{tabularx}
\end{document}

aligned squares

You must log in to answer this question.

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