3

Trying to make a table with the following code

\begin{table}[h]
\caption{Different scans conducted with the Catphan.}
\begin{tabularx}{\linewidth}{|l|X|X|c|X|}
\hline
\rowcolor{slightgray}
\T Phantoms &Mode  &Position &Times Scanned &mAs\B\\
\hline
\cellcolor{slightgray}\T Catphan &Head-Slow &Centered &1 &60\B\\
\hline
\cellcolor{slightgray}\T Catphan &Head &Centered &10 &60\B\\
\hline
\cellcolor{slightgray}\T Catphan &Pelvis &Centered &1 &60\B\\
\hline 
\cellcolor{slightgray}\T Catphan and Annulus &Pelvis &Centered &1 &60\B\\
\hline 
\cellcolor{slightgray}\T Catphan and Annulus &Pelvis &Centered &1 &100\B\\
\hline 

\end{tabularx}
\label{tab:example}
\end{table}

The table that I get looks like : enter image description here

I cannot figure out why there is a horizontal line under the first Catphan and a vertical line before and after Times Scanned column heading.

I am using a latex template. First I thought \T and \B are part or tabularx but upon inspection could not find them. In the example with the template \T and \B are mentioned to increase the cell size slightly. I removed all \T and \B from the code and the result looks like: enter image description here

The vertical lines seem to go away and the horizontal line moves down a row. @David Thanks for the reply. I moved the caption down and it seems to be working fine. I guess I should look into the backend before posting here. Anyway thanks for the help!

3
  • 1
    Welcome to SE! That we can help ypu, please complete your code fragment so, that we can copy and compile it! What is for example \T and B?
    – Zarko
    Commented Feb 3, 2016 at 13:47
  • 1
    you have \caption before the table in the source, by default that would make it appear before the table, but you show it coming after, so you hav eused something that redefines caption (possibly caption package) and that something may have redefined it to have rules above and below, but impossible to describe code that has not been shown. Commented Feb 3, 2016 at 13:55
  • the vertical lines are easy, you have specified vertical lines with | Commented Feb 3, 2016 at 13:56

2 Answers 2

2

Even after your edit of question it is still cryptic to me. So on basis of guessing and a bit of considering, how I will wrote similar table, I made the following example:

enter image description here

\documentclass{article}
\usepackage{tabularx}
\usepackage[table]{xcolor}
\usepackage{siunitx}

\begin{document}
\begin{table}[h]
\renewcommand{\arraystretch}{1.5}
\sffamily
    \caption{Different scans conducted with the Catphan.}
\begin{tabularx}{\linewidth}{lXX*2{S[table-format=2.0]}}%>{\columncolor{gray!30}}
\hline
\rowcolor{gray!30}
Phantoms &Mode  &Position &{Times Scaned} &{mAs} \\
\hline
Catphan &Head-Slow &Centered &1 &60 \\
\hline
Catphan &Head &Centered &10 &60 \\
\hline
Catphan &Pelvis &Centered &1 &60 \\
\hline
Catphan and Annulus &Pelvis &Centered &1 &60\\
\hline
Catphan and Annulus &Pelvis &Centered &1 &100\\
\hline
\end{tabularx}
\label{tab:example}
\end{table}
    \end{document}    

Edit: With use of package caption the distance between caption and table is bigger (as mentioned Bernard in his comment). Also without horizontal lines the table look better:

enter image description here

Modified code is:

\documentclass{article}
\usepackage{tabularx}
\usepackage[table]{xcolor}

\usepackage{siunitx}
\usepackage{caption}

\begin{document}
\begin{table}[h]
\renewcommand{\arraystretch}{1.3}
\sffamily
    \caption{Different scans conducted with the Catphan.}
\begin{tabularx}{\linewidth}{%>{\columncolor{gray!30}}
                             lXX*2{S[table-format=2.0]}}
\hline
\rowcolor{gray!30}
Phantoms &Mode  &Position &{Times Scaned} &{mAs} \\
\hline
Catphan &Head-Slow &Centered &1 &60 \\
Catphan &Head &Centered &10 &60 \\
Catphan &Pelvis &Centered &1 &60 \\
Catphan and Annulus &Pelvis &Centered &1 &60\\
Catphan and Annulus &Pelvis &Centered &1 &100\\
\hline
\end{tabularx}
\label{tab:example}
\end{table}
    \end{document}    
2
  • You should load caption to have a sensible skip between caption and table when caption is above table.
    – Bernard
    Commented Feb 3, 2016 at 15:25
  • Yes, with caption it will look nicer. I will upgrade my answer.
    – Zarko
    Commented Feb 3, 2016 at 15:31
1

I propose another layout, based on tabular only:

\documentclass{article}
\usepackage[table, x11names]{xcolor}
\usepackage{graphicx}
\usepackage{caption, makecell}
\renewcommand\theadfont{\normalsize}
\renewcommand\theadalign{bc}
\usepackage{siunitx}
\usepackage{etoolbox}
\colorlet{slightgray}{LightSteelBlue3!25}
\patchcmd{\Xhline}{\hrule}{\color{SteelBlue4}\hrule}{}{}

\begin{document}

\begin{table}[h]
  \centering
  \sffamily\renewcommand\arraystretch{1.333}\arrayrulecolor{red}
  \captionsetup{font=sf}
  \caption{Different scans conducted with the Catphan.}\label{tab:example}
  \begin{tabular}{>{\columncolor{slightgray}}l!{\color{SteelBlue4}\vrule width1.8pt}lcc S[table-format=3.0, detect-family]}
    \rowcolor{slightgray}
    Phantoms & Mode & Position & \thead{Times \\ Scanned} & {mAs} \\
    \Xhline{1.2pt}%
    Catphan & Head-Slow & Centered & 1 & 60 \\
    Catphan & Head & Centered & 10 & 60 \\
    Catphan & Pelvis & Centered & 1 & 60 \\
    Catphan and Annulus & Pelvis & Centered & 1 & 60 \\
    Catphan and Annulus & Pelvis & Centered & 1 & 100 \\
  \end{tabular}
\end{table}

\end{document} 

enter image description here

You must log in to answer this question.

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