0

I have been trying for several hours to achieve the following appearance using tabularx with no success:

  • Column 1: Aligned vertical top, horizontal right.
  • Column 2: Aligned vertical top, horizontal left.
  • Column 3: Aligned vertical top, horizontal left, expanding width (e.g. X).
  • Columns 4,5,6: Aligned vertical bottom, horizontal right

I managed to get last three columns aligned vertically at bottom relative to the 'Long Text' column, but this had undesired effects on the first two column which are now also vertically aligned bottom. How can I align the first two columns vertically at the top while keeping the other columns as they are?

Table Source:

\begin{table}
\renewcommand{\tabularxcolumn}[1]{b{#1}}
\newcolumntype{R}{>{\raggedleft\arraybackslash}p{0.9cm}}
\begin{tabularx}{\textwidth}[ht]{|r|p{2.7cm}|X|R|R|R|}
\hline
\textbf{\texttt \#} &
\textbf{Info} &
\textbf{Long Text} &
{\raggedright \bfseries Col 1 \\(foo.)} &
{\raggedright \bfseries Col 2 \\(bar.)} &
{\raggedright \bfseries Col 3 \\(baz.)}
\\ \hline
1 & \raggedright One, \newline thing & \lipsum*[1] &
    1.11 &
    2.22 &
    3.33 \\ \hline

2 & \raggedright Some, \newline Thing & \lipsum*[1] &
    1.55 &
    3.66 &
    6.99 \\ \hline

\end{tabularx}
\caption{XXX}
\label{tab:xxx}
\end{table}

Table Appearance:

The red arrows show how cell content should move to achieve the desired result.

![Table Cell Alignment

Update: Clarified the desired result.

  • What you're trying to achieve is not very clear to me (what does ‘vertical top’ mean?). Could you explain what's wrong in the above result? – Bernard Jul 5 '18 at 11:49
  • @Bernard He/She possibly means: vertical alignment ->top, horizontal -> right etc... – koleygr Jul 5 '18 at 11:52
  • The first two columns should be vertically aligned at the top of the cell, that is I want the 1 and 2 of the first column to be vertically aligned with the first line of the long text column. Same for the Info column, there the One and the Some should be aligned vertically with the Lorem. – lanoxx Jul 5 '18 at 11:53
  • I have updated the question to hopefully be more clear. – lanoxx Jul 5 '18 at 11:57
1

I propose this dirty hack: using \multirow{-n} in the first two columns. n is approximately twice the number of lines in the next X cell.

\documentclass[10pt]{article}
\usepackage{geometry}
\usepackage{tabularx, makecell, multirow}
\usepackage{lipsum}

    \begin{document}

\begin{table}
\renewcommand{\tabularxcolumn}[1]{b{#1}}
\newcolumntype{R}{>{\raggedleft\arraybackslash}b{1cm}}
\begin{tabularx}{\textwidth}[ht]{|r|p{2.7cm}|X|R|R|R|}
\hline
\textbf{\texttt \#} &
\textbf{Info} &
\textbf{Long Text} &
{\raggedright \bfseries Col 1 \\(foo.)} &
{\raggedright \bfseries Col 2 \\(bar.)} &
{\raggedright \bfseries Col 3 \\(baz.)}
\\ \hline
\multirowcell{-41}{1 }& \multirow{-40}{=}{One, \\ thing} & \lipsum*[1] &
    1.11 &
    2.22 &
    3.33 \\ \hline

\multirowcell{-41}{2} & \multirow{-40}{=}{Some, \\ Thing} & \lipsum*[1] &
    1.55 &
    3.66 &
    6.99 \\ \hline

\end{tabularx}
\caption{XXX}
\label{tab:xxx}
\end{table}

\end{document} 

enter image description here

| improve this answer | |
  • Could you explain the meaning of the values -41 and -40? – lanoxx Jul 5 '18 at 13:52
  • @Ianoxx: each X cell on the right-hand side has 20 lines, so I tried with -40, and adjusted for the 1st column (its text uses a single line., whereas the 2nd has 2. It's really by trial and error. Also, multirow accepts an optional argument for fine-tuning the placement of its content, if necessary. – Bernard Jul 5 '18 at 14:10
  • Thanks, I experimented a bit with this solution and just came to the same conclusion it gives the desired results but it requires that I adjust the values of the first parameter of \multirow and \multirowcell for each table row to reflect the number of text lines in that row. This is quite fragile, is there a way to compute the number of rows somehow? – lanoxx Jul 5 '18 at 14:11
  • I don't know of any, but maybe some LaTeX guru knows. B.t.w., \multirow now accepts non-integer values, which may help fine-tuning. – Bernard Jul 5 '18 at 14:17
1

I'd use a simple table definition dividing every row into two and shifting up the second row with \\[...].

\documentclass[10pt]{article}
\usepackage{geometry}
\usepackage{tabularx, makecell, multirow}
\usepackage{array}
\renewcommand{\arraystretch}{1.3}
\usepackage{lipsum}

\begin{document}
\begin{table}\centering
\begin{tabular}{|p{.6em}|p{2.7em}|p{23em}|c|c|c|}
\hline
\textbf{\texttt \#} & \textbf{Info} & \textbf{Long Text} & \textbf{Col 1} &
    \textbf{Col 2} & \textbf{Col 3}\\[-4pt]
 & & & \textbf{(foo.)} & \textbf{(bar.)} & \textbf{(baz.)}\\ 
\hline
1& One, thing & \lipsum*[1] & & & \\[-3.5ex] 
\multicolumn{1}{c}{}&\multicolumn{1}{c}{} &\multicolumn{1}{c}{}  &
    \multicolumn{1}{c}{1.11} &
    \multicolumn{1}{c}{2.22} &
    \multicolumn{1}{c}{3.33} \\ 
\hline
2 & Some, Thing & \lipsum*[1] & & & \\[-3.54ex] 
\multicolumn{1}{c}{}&\multicolumn{1}{c}{} &\multicolumn{1}{c}{}  &
    \multicolumn{1}{c}{1.55} &
    \multicolumn{1}{c}{3.66} &
    \multicolumn{1}{c}{6.99} \\ 
\hline
\end{tabular}
\caption{XXX}\label{tab:xxx}
\end{table}
\end{document}

-

| improve this answer | |

Your Answer

By clicking “Post Your Answer”, you agree to our terms of service, privacy policy and cookie policy

Not the answer you're looking for? Browse other questions tagged or ask your own question.