TeX - LaTeX Stack Exchange is a question and answer site for users of TeX, LaTeX, ConTeXt, and related typesetting systems. It's 100% free, no registration required.

Sign up
Here's how it works:
  1. Anybody can ask a question
  2. Anybody can answer
  3. The best answers are voted up and rise to the top

tabularx with a \newcolumntype and \multicolumn adds another incomplete column to the right side

\documentclass{article}
\usepackage{tabularx}

\newcolumntype{s}{>{\hsize=0.5\hsize}  X}

\begin{document}
  \begin{tabularx}{0.5\textwidth}{ |s|X|}
    \hline
    \multicolumn{2}{|X|}{Item}\\
    \hline
    a & b\\
    \hline 
    c & d \\
    \hline
  \end{tabularx}
\end{document}

where does this come from and how can I remove it?

table

share|improve this question
up vote 4 down vote accepted

To have two X columns, one of them being half as wide as the other, it is not a coefficient of 0.5you have to choose, but 2 coefficients such that their sum is 2, one of them being half the other. In other words $2/3$ and $4/3$.

For the multicolumn (which is not recommended here), use the l specifier, not X. The X specifier leads to a multicolumn that is half the table wide.

\documentclass{article}
\usepackage[showframe]{geometry}
\usepackage{multirow, tabularx}
\newcolumntype{s}{>{\hsize=0.667\hsize\arraybackslash} X}
\newcolumntype{Y}{>{\hsize=1.333\hsize\arraybackslash} X}

\begin{document}

\vspace*{1cm}
\noindent \begin{tabularx}{0.5\textwidth}{ |s| >{\arraybackslash}Y|}
    \hline
 \multicolumn{2}{|l|}{Item}\\
    \hline
    a & b\\
    \hline
    c & d \\
    \hline
  \end{tabularx}

\end{document} 

enter image description here

share|improve this answer
    
if I had 3 columns, would the sum have to be 3, too? and so on? also why is multicolumn not recomended and what alterantiv would be better? – Max Eisel Feb 29 at 21:02
    
Yes, the sum of the coefficients must be equal to the number of columns. \multicolumn is not recommended in case you have X type columns of different widths, as here. I don't know why, I suppose calculations of the package might be perturbated. It's written in § 4.3, p. 3 of the documentation, which adds this rule may be broken if you know what you're doing. The alternative would be to use a p{…} column, with a width approximately.determined. – Bernard Feb 29 at 21:59

Your Answer

 
discard

By posting your answer, you agree to the privacy policy and terms of service.

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