1

The following commands can be used to customize X column with a parameter for adjusting width as well as horizontal alignment in tabularx.

\newcolumntype{L}[1]{>{\hsize=#1\hsize\raggedright\arraybackslash}X}%
\newcolumntype{R}[1]{>{\hsize=#1\hsize\raggedleft\arraybackslash}X}%
\newcolumntype{C}[1]{>{\hsize=#1\hsize\centering\arraybackslash}X}%

Here is an modified example from the wikibook:

\documentclass[letterpaper,12pt]{letter}
\usepackage{tabularx}
\usepackage[table]{xcolor} %Used to color the last column


\newcolumntype{L}[1]{>{\hsize=#1\hsize\raggedright\arraybackslash}X}%
\newcolumntype{R}[1]{>{\hsize=#1\hsize\raggedleft\arraybackslash}X}%
\newcolumntype{C}[1]{>{\hsize=#1\hsize\centering\arraybackslash}X}%

\begin{document}
\begin{tabularx}{\textwidth}{ | L{1} | R{0.5} | R{0.5} | C{2} | }
    \hline
    label 1  & label lable 2 & label  & label 4  \\
    \hline
    item 1  & item 2  & item 3  & item 4  \\
    \hline
\end{tabularx}
\end{document}

The resutl is: enter image description here

From the figure, we can see the texts are vertically aligned at the top. My question is that how to modify these commands to also support the vertical alignment of these columns.

Yulong Ao
  • 723
  • What's the problem? You already have an example of how to go from 1 parameter to 2. But your question seems confused - what's b in this context and how do you plan to use the parameter? The lack of example doesn't help, of course. – cfr Nov 03 '16 at 04:30
  • @cfr, I have clarified the question. – Yulong Ao Nov 03 '16 at 05:50
  • By "vertical alignment ", do you mean vertical centering? – Mico Nov 03 '16 at 06:58
  • @Mico: It's better to choose the top, center, or bottom alignment by passing a parameter. For now, vertical centering is OK. – Yulong Ao Nov 03 '16 at 07:07
  • Use \renewcommand{\tabularxcolumn}[1]{m{#1}} for "middle" vertical positioning and \renewcommand{\tabularxcolumn}[1]{b{#1}} for "bottom" positioning. (The default, as you've noticed, is t.) This has got to be a duplicate query, though -- I'm sure this issue has come up multiple times so far on this site. – Mico Nov 03 '16 at 07:24

0 Answers0