1

Problems:

Extra alignment tab has been changed to \cr.

Which I think means something like the LaTeX code has a different amount of cells in this row than what was defined in the tabularx premable.

The issue doesn't exist until I attempt to add more rows after the header, but the last cell on the right is sort of...elevated? I don't quite understand the problem here, I mean in a tabularx environment you separate cells by & and end a row by // , right?

Also, if you change the last header title to: {\centering T} it doesn't crash or elevate the text but...it doesn't center the text.

Any ideas?

NOTES: The bigger picture here is that I want to align the header differently than the cells. So I'm trying to just use \centering on the header. \begin{center} does it but puts a ton of space around it.

MWE:

\documentclass[11pt]{letter}                              
\usepackage[letterpaper, inner=18mm, outer=18mm, top=8mm, bottom=25mm]{geometry}
\usepackage{tabularx}                                               
\usepackage[table,xcdraw]{xcolor}
    
\renewcommand{\tabularxcolumn}[1]{>{\tiny}m{#1}}
\newcolumntype{x}{>{\raggedleft\arraybackslash}X}  
        
\begin{document}

    \rowcolors{1}{}{gray!15}
        \begin{tabularx}{\textwidth}{xxxxxxxxxxxx}
            \rowcolor{gray}

    \color{white}\fontsize{6pt}{6pt}\selectfont \centering Text  &          
    \color{white}\fontsize{6pt}{6pt}\selectfont \centering text &   
    \color{white}\fontsize{6pt}{6pt}\selectfont \centering Text &   
    \color{white}\fontsize{6pt}{6pt}\selectfont \centering Text  &  
    \color{white}\fontsize{6pt}{6pt}\selectfont \centering Text &   
    \color{white}\fontsize{6pt}{6pt}\selectfont \centering Text  &  
    \color{white}\fontsize{6pt}{6pt}\selectfont \centering Text  &  
    \color{white}\fontsize{6pt}{6pt}\selectfont \centering Text  &  
    \color{white}\fontsize{6pt}{6pt}\selectfont \centering Text Text Text &     
    \color{white}\fontsize{6pt}{6pt}\selectfont \centering Text  &  
    \color{white}\fontsize{6pt}{6pt}\selectfont \centering Text  &  
    \color{white}\fontsize{6pt}{6pt}\selectfont {\centering Tt} \\  

    \color{black}\fontsize{6pt}{6pt}\selectfont 8'  & 
    \color{black}\fontsize{6pt}{6pt}\selectfont 130  & 
    \color{black}\fontsize{6pt}{6pt}\selectfont 134  & 
    \color{black}\fontsize{6pt}{6pt}\selectfont 152  & 
    \color{black}\fontsize{6pt}{6pt}\selectfont 168  & 
    \color{black}\fontsize{6pt}{6pt}\selectfont 200  & 
    \color{black}\fontsize{6pt}{6pt}\selectfont 240  & 
    \color{black}\fontsize{6pt}{6pt}\selectfont 340  & 
    \color{black}\fontsize{6pt}{6pt}\selectfont 520  & 
    \color{black}\fontsize{6pt}{6pt}\selectfont 340  & 
    \color{black}\fontsize{6pt}{6pt}\selectfont 520  & 
    \color{black}\fontsize{6pt}{6pt}\selectfont -  \\

\end{tabularx}
\end{document}

Edit:

Firstly, it may seem really inconvenient how I'm repeating a lot of things but really I'm just typing it once and the computer is repeating it in a loop.

I haven't been using multicolumn because the headers extend past the table cells widths and I cannot define a static width for each cell (or I wouldn't have a problem) because in the BIGGER picture I'm templating the LaTeX file with Scriban and I'm dealing with a dynamic header. Here is what happens when using multicolumn:

enter image description here

I was able to center the headers with \begin{center} but the space around each header cell was undesirable, so I looked it up and tried a new environment here: How can I change the whitespace above and below center? which was able to remove the space above, but not below. I placed the \begin and \end{center} right before and after each header cell. Here is what that looks like:

enter image description here

I don't need tiny cells, I just thought that would change the width multicolumn forcing for the headers.

I was just puzzled because tabular is reacting weirdly to the \centering modifier in each line.

Also, I am using tabularX because it extends it dynamically to the end of the page.

  • You can use \multicolumn{1}{c}{...} in order to horizontally center the text of a single cell. An alternative would be the \thead command from the makecell package. – leandriis Jul 1 at 21:08
  • Could you please add some background information on the other contents of the table? Will you need linebreaks inside of table cells? Also, why do you need all teh repeated \color{black}\fontsize{6pt}{6pt}\selectfont? Why do you need a \tiny font size here? – leandriis Jul 1 at 21:11
  • you could use \centering\arraybackslash just as you used \raggedright\arraybackslash but there is no line breaking within the cells so you shouldn't be using tabularx here, just use tabular – David Carlisle Jul 1 at 21:45
  • also you do not need to specify the color and font size in every cell, just specify them once before the table – David Carlisle Jul 1 at 21:47
  • @DavidCarlisle David to the rescue again. The answer is that the \arraybackslash needed to be right after \centering. How come that's the case, what does the \arraybackslash really do for tabular? – tblev Jul 2 at 14:15
0

Replace

\color{white}\fontsize{6pt}{6pt}\selectfont \centering Text  &

with

\color{white}\fontsize{6pt}{6pt}\selectfont \centering\arraybackslash Text  &
| 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.