4

I've just recently started to use LaTeX and It's been wonderful. However, I've been struggling with tables in general.

This is by far my best table creation but still isn't perfect. As you can see caption's table is not properly center and "Constant current" from Tektronix and Maynuo's column have too much space between cells.

enter image description here

Here's my code, I'll put all packages in case there's something wrong there.

\documentclass[11pt,twoside,a4paper]{report}    
\usepackage[utf8]{inputenc}
\usepackage[spanish]{babel}
\usepackage[T1]{fontenc}
\usepackage[margin=3cm]{geometry}
\usepackage{url, graphicx}

\usepackage[center]{caption}

\usepackage{multirow}   
\usepackage{gensymb}    
\usepackage{enumitem}   

\raggedbottom       

\usepackage{helvet}                 
\renewcommand{\familydefault}{\sfdefault}       

\setlength{\parindent}{0pt}         
\setlength{\parskip}{1em}               
\renewcommand{\baselinestretch}{1.5}    

\usepackage[notlot,notlof,nottoc,notindex]{tocbibind}   
\usepackage{titlesec}
\titleformat{\chapter}[display]   
{\normalfont\huge\bfseries}{\chaptertitlename\ \thechapter}{20pt}{\Huge}   
\titlespacing*{\chapter}{0pt}{-50pt}{40pt}

\usepackage{array}      
\newcolumntype{L}[1]{>{\raggedright\let\newline\\\arraybackslash\hspace{0pt}}m{#1}}
\newcolumntype{C}[1]{>{\centering\let\newline\\\arraybackslash\hspace{0pt}}m{#1}}
\newcolumntype{R}[1]{>{\raggedleft\let\newline\\\arraybackslash\hspace{0pt}}m{#1}}

\usepackage{booktabs}       
\newcommand{\tabitem}{~~\llap{\textbullet}~~}

\usepackage{changepage} 

\begin{document}

\section{Introduction}

\begin{table}[htbp]
\begin{adjustwidth}{-2.5cm}{}
\renewcommand{\arraystretch}{1}
\footnotesize
\begin{center}
\caption{Comparación de características entre los instrumentos actuales para baterías en el mercado}
\begin{tabular}{|L{2cm}|C{3cm}|C{3cm}|C{3cm}|C{3cm}|C{3cm}|}\cline{2-6}
\multicolumn{1}{c|}{} & \textbf{Cadex C7600~\cite{Cadexcompany}} & \textbf{Cadex C8000~\cite{Company}} & \textbf{NI PXI-4130~\cite{NationalInstruments2000}} &                    \textbf{Tektronix 2380~\cite{KEITHLEYaTektronixCompany}} & \textbf{Maynuo M9712C~\cite{MaynuoElectronic}}\\\hline  
\multicolumn{1}{|L{2.5cm}|}{Battery voltage range} & 1.2V - 36V & 1.2V - 36V & 0 - 20V & 0 - 500V & 0.1V - 150V \\\hline
\multicolumn{1}{|L{2.5cm}|}{\multirow{4}{*}{Discharge method}} &\multirow{4}{*}{Constant current} & \multirow{2}{*}{Constant current} & \multirow{2}{*}{Constant current} & Constant current & Constant current \\  &  & &  & Constant voltage & Constant voltage \\ &  & \multirow{2}{*}{Constant power} & \multirow{2}{*}{Constant voltage} & Constant resistance & Constant          resistance \\ &  &  &  & Constant power & Constant power \\\hline
\multicolumn{1}{|L{2.5cm}|}{Range of discharge current} & 100mA - 6A & 30mA - 10A & 2mA - 20mA & 0 - 15A & 0 - 6A \\\hline
\multicolumn{1}{|L{2.5cm}|}{Resolution} & 25 mA & 1mA & 100nA & 1 mA & 0.01 mA \\\hline
\multicolumn{1}{|L{2.5cm}|}{Exactitud} & 0.25\% FS & 0.25\% FS & 0.03\% FS & (0.05\% FR + 0.05\% FS) & 0.015\%FR + 0.05\%FS \\\hline
\multicolumn{1}{|L{2.5cm}|}{Operating Temperature} & 5\degree C - 35\degree C & 5\degree C - 35\degree C & 0\degree C - 55\degree C & 0\degree C - 40\degree C & 0\degree C - 40\degree C \\\hline
\multicolumn{1}{|L{2.5cm}|}{Display} & 2x40-character LCD & 5.7'' (145mm) QVGA 320x240 graphics with backlight & There isn’t available information & Monitor Output BNC & High-luminance VFD screen with two line \\\hline
\multicolumn{1}{|L{2.5cm}|}{Data ports} & RS-232 or USB interfaces to PC & Ethernet 10/100 MB for connection to PC & There isn’t available information & USB, RS-232, GPIB & USB, RS232, RS485 \\\hline
\end{tabular}
\end{center}
\end{adjustwidth}
\end{table}

\end{document}

I'd appreciate any help and any suggestion to improve my table. Thanks in advance!

5
  • Welcome to TeX.SE. You shouldn't use \begin{center}...\end{center} inside of a floating environment such as table. Use \centering instead of \begin{center} and remove the \end{center} part, this should center the caption as well, normally, but your table is just too wide, it leaks into the right margin
    – user31729
    Commented Apr 11, 2017 at 7:32
  • @Jeancarlo - Did you use Excel2LaTex to produce the table or did you write it from scratch yourself?
    – gnikit
    Commented Apr 11, 2017 at 7:33
  • As well as the units should be typeset with the \SI macro from the siunitx package
    – user31729
    Commented Apr 11, 2017 at 7:36
  • @ChristianHupfer Well then I was so wrong because I've been using \begin{center}...\end{center} for almost all my figures and tables. I didn't know about that floating enviroment, I'll look into that for sure. Thank you ! By the way, how it would be the right way to use begin,end center? P.s: Thanks for SI package tip Commented Apr 16, 2017 at 23:07
  • @nikjohn I wrote it from scratch. Commented Apr 16, 2017 at 23:08

3 Answers 3

3

Like this?

enter image description here

Edit: column type are changed from raggedright to centering, corrected wrong use of adjustwidth environment from package changepage. It is now loaded with option strict and adopted to use in the two side documents.

In your table I first remove all surplus \multicolumn{1}{...}{....}, than for \multirow use option = which preserve column formatting in multi row cells, reduce \tabcolsep to half of default value and for table use tabularx environment. Changes are in column type definitions too. Now C is accommodated to tabularx column type.

Instead of \begin{center} ... \end{center} is better to use \centering, which doesn't add vertical space around table.

In caption I remove option center (in packagecenter it not exist) and for font size select \small. Also I reduce distance between caption and table with skip=1ex. For units is used package siunitx.

\documentclass[11pt,twoside,a4paper]{report}
\usepackage[utf8]{inputenc}
\usepackage[spanish]{babel}
\usepackage[T1]{fontenc}
\usepackage[margin=3cm]{geometry}
\usepackage{graphicx}

\usepackage[font=small,skip=1ex]{caption}% <-- changed

\usepackage{gensymb}
\usepackage{enumitem}

\raggedbottom

\usepackage{helvet}
\renewcommand{\familydefault}{\sfdefault}

\setlength{\parindent}{0pt}
\setlength{\parskip}{1em}
\renewcommand{\baselinestretch}{1.5}

\usepackage[notlot,notlof,nottoc,notindex]{tocbibind}
\usepackage{titlesec}
\titleformat{\chapter}[display]
{\normalfont\huge\bfseries}{\chaptertitlename\ \thechapter}{20pt}{\Huge}
\titlespacing*{\chapter}{0pt}{-50pt}{40pt}

\usepackage{booktabs, multirow, tabularx}
\newcolumntype{L}[1]{>{\raggedright\arraybackslash}m{#1}}
\renewcommand\tabularxcolumn[1]{m{#1}}
\newcolumntype{C}{>{\centering\arraybackslash}X}

\usepackage{changepage}
\usepackage[range-phrase = \,--\,]{siunitx}
\usepackage{url}

\begin{document}

\section{Introduction}

\begin{table}[htbp]
\begin{adjustwidth*}{}{-2.5cm}
    \centering
\renewcommand{\arraystretch}{1}
\setlength\tabcolsep{3pt}
\footnotesize
    \caption{Comparación de características entre los instrumentos actuales para baterías en el mercado}
\begin{tabularx}{\linewidth}{| L{2cm} |
            >{\hsize=0.9\hsize}C |       
                        *{3}{C |}
            >{\hsize=1.1\hsize}C |
                             }
    \cline{2-6}
\multicolumn{1}{c|}{}
    &   \textbf{Cadex C7600~\cite{Cadexcompany}} 
        &   \textbf{Cadex C8000~\cite{Company}} 
            &   \textbf{NI PXI-4130~\cite{NationalInstruments2000}} 
                &   \textbf{Tektronix 2380~\cite{KEITHLEYaTektronixCompany}} 
                    &   \textbf{Maynuo M9712C~\cite{MaynuoElectronic}}              \\
    \hline
Battery voltage range   
    & \SIrange{1.2}{36}{V} & \SIrange{1.2}{36}{V} & \SIrange{0}{20}{V} 
        & \SIrange{0}{500}{V} & \SIrange{0.1}{150}{V} \\
    \hline
\multirow{4}{=}{Discharge method}
    &   \multirow{4}{=}{Constant current} 
        &   \multirow{2}{=}{Constant current} 
            &   \multirow{2}{=}{Constant current} 
                &   Constant current 
                    &   Constant current            \\  
    &   &   &   &   Constant voltage 
                    &   Constant voltage            \\ 
    &   &   \multirow{2}{*}{Constant power} 
            &   \multirow{2}{*}{Constant voltage} 
                    &   Constant resistance 
                        &   Constant resistance     \\ 
    &   &   &   &   Constant power 
                        & Constant power            \\
    \hline
Range of discharge current
    & \SIrange{0.1}{6}{A} & \SIrange{0.03}{10}{A} 
        & \SIrange{2}{20}{mA} & \SIrange{0}{15}{A} & \SIrange{0}{6}{A}  \\
    \hline
Resolution       
    & \SI{25}{mA} & \SI{1}{mA} & \SI{100}{nA} & \SI{1}{mA} & \SI{0.01}{mA} \\
    \hline
Exactitud        
    & \SI{0.25}{\%} FS & \SI{0.25}{\%} FS & \SI{0.03}{\%} FS 
        & (\SI{0.05}{\%} FR + \SI{0.05}{\%} FS) & \SI{0.015}{\%} FR + \SI{0.05}{\%} FS \\
    \hline
Operating Temperature
    & \SIrange{5}{35}{\degreeCelsius} & \SIrange{5}{35}{\degreeCelsius} 
        & \SIrange{0}{55}{\degreeCelsius} & \SIrange{0}{40}{\degreeCelsius} 
            & \SIrange{0}{40}{\degreeCelsius}\\
    \hline
Display  & 2x40-character LCD & \SI{5.7}{''} (145mm) QVGA 320x240 graphics with backlight & There isn’t available information & Monitor Output BNC & High-luminance VFD screen with two line \\
    \hline
Data ports  & RS-232 or USB interfaces to PC & Ethernet 10/100 MB for connection to PC & There isn’t available information & USB, RS-232, GPIB & USB, RS232, RS485 \\
    \hline
\end{tabularx}
\end{adjustwidth*}
\end{table}

\end{document}

The problem with centering in your MWE probably arise from used definition of column type C and since the last column require slightly wider column width as is defined. Because you not use english babel, LaTeX doesn't know how to hyphenate English word, so it make spurious centering.

2
  • Thanks for the answer ! It looks way cleaner than my code. However, I'm not able to compile because it throws me this error: ! File ended while scanning use of \TX@get@body. <inserted text> \par <*> C:/Jeancarlo/test/test.tex I'm using TeXworks' software. Also I tried compiling in sharelatex but didn't work. Which software do u use to compile tex files? Commented Apr 16, 2017 at 23:40
  • I use recent MikTeX 64-bit installation with recent package repository on my PC and for editor use WinEdt. I test proposed solution and discover, that the code is not the last version and it contain error in columns definition: instead of *{3}{>{C |} had to be *{3}{C |}. Sorry for all inconvenience. Now the code is corrected and tested!
    – Zarko
    Commented Apr 16, 2017 at 23:59
1

I suggest you set both arguments of \adjustwidth to -2.5cm, not just the first one. This will automatically give you a centered caption. For the two-row and four-row material in some of the cells, I suggest you use tabular environments rather than \multirow directives. Indeed, the code shown below doesn't use any \multirow instructions at all.

enter image description here

\documentclass[11pt,twoside,a4paper]{report}
\usepackage[utf8]{inputenc}
\usepackage[spanish]{babel}
\usepackage[T1]{fontenc}
\usepackage[margin=3cm]{geometry}
\usepackage{url, graphicx}

\usepackage[skip=0.333\baselineskip]{caption}

%%\usepackage{multirow} % no longer needed
\usepackage{gensymb}
\usepackage{enumitem}
\usepackage{ragged2e}
\raggedbottom

\usepackage{helvet}
\renewcommand{\familydefault}{\sfdefault}

\usepackage{parskip} %
%\setlength{\parindent}{0pt}
%\setlength{\parskip}{1em} % not a good idea to make this a rigid length!
\parskip=1em \advance\parskip by 0pt plus 2pt

\usepackage{setspace}
\setstretch{1.5} % don't change "\baselinestretch" directly

\usepackage[notlot,notlof,nottoc,notindex]{tocbibind}
\usepackage{titlesec}
\titleformat{\chapter}[display]
{\normalfont\huge\bfseries}{\chaptertitlename\ \thechapter}{20pt}{\Huge}
\titlespacing*{\chapter}{0pt}{-50pt}{40pt}

\usepackage{array}
\newcolumntype{L}[1]{>{\RaggedRight\let\newline\\\arraybackslash\hspace{0pt}}m{#1}}
\newcolumntype{C}[1]{>{\Centering\let\newline\\\arraybackslash\hspace{0pt}}m{#1}}
\newcolumntype{R}[1]{>{\raggedleft\let\newline\\\arraybackslash\hspace{0pt}}m{#1}}

\usepackage{booktabs}
\newcommand{\tabitem}{~~\llap{\textbullet}~~}

\usepackage{changepage} % for "\adjustwidth" macro
\usepackage[detect-all]{siunitx}

\hyphenation{dis-charge volt-age method infor-mation}

\begin{document}
\setcounter{chapter}{2} % just for this example

\begin{table}[htbp]
\begin{adjustwidth}{-2.5cm}{-2.5cm}
\setlength\extrarowheight{2.5pt}
\captionsetup{size=small}
\footnotesize
\centering
\caption{Comparación de características entre los 
instrumentos actuales para baterías en el mercado}
\begin{tabular}{| L{2.25cm} | *{5}{C{3cm}|}}
\cline{2-6}
\multicolumn{1}{c|}{} 
& \textbf{Cadex C7600~\cite{Cadexcompany}} 
& \textbf{Cadex C8000~\cite{Company}} 
& \textbf{NI PXI-4130~\cite{NationalInstruments2000}} 
& \textbf{Tektronix 2380~\cite{KEITHLEYaTektronixCompany}} 
& \textbf{Maynuo M9712C~\cite{MaynuoElectronic}}\\
\hline
Battery voltage range & \SI{1.2}{\volt}--\SI{36}{\volt} 
& \SI{1.2}{\volt}--\SI{36}{\volt} & 0--\SI{20}{\volt} 
& 0--\SI{500}{\volt} & \SI{0.1}{\volt}--\SI{150}{\volt} \\
\hline
Discharge method & Constant current & 
\begin{tabular}{@{}c@{}}
Constant current \\ \\ Constant power 
\end{tabular} &
\begin{tabular}{@{}c@{}}
Constant current \\ \\ Constant voltage
\end{tabular} &
\begin{tabular}{@{}c@{}}
Constant current \\ Constant voltage \\ Constant resistance \\ Constant power 
\end{tabular} &
\begin{tabular}{@{}c@{}}
Constant current \\ Constant voltage \\ Constant resistance \\ Constant power
\end{tabular} \\
\hline
Range of discharge current & 100mA--6A & 30mA--10A & 2mA--20mA & 0--15A & 0--6A \\
\hline
Resolution & 25mA & 1mA & 100nA & 1mA & 0.01mA \\
\hline
Exactitud & 0.25\% FS & 0.25\% FS & 0.03\% FS & (0.05\% FR + 0.05\% FS) & 0.015\%FR + 0.05\%FS \\
\hline
Operating Temperature & \SI{5}{\celsius}--\SI{35}{\celsius} 
& \SI{5}{\celsius}--\SI{35}{\celsius} & \SI{0}{\celsius}--\SI{55}{\celsius} 
& \SI{0}{\celsius}--\SI{40}{\celsius} & \SI{0}{\celsius}--\SI{40}{\celsius} \\
\hline
Display & 2$\times$40-character LCD & 5.7'' (145mm) QVGA 320$\times$240 graphics with backlight & No information available & Monitor Output BNC & High-luminance VFD screen with two line \\
\hline
Data ports & RS-232 or USB interfaces to PC & Ethernet 10/100 MB for connection to PC & No information available & USB, RS-232, GPIB & USB, RS232, RS485 \\
\hline
\end{tabular}
\end{adjustwidth}
\end{table}

\end{document} 
1

Here are some improvements, with siunitx, makecell, stackengine and ordinary cells. Makecell is designed to allow for line breaks inside cells. A lighter code: no multirow, no nested tabular. Playing with tabcolsep, I only add 1.5cm on each side.

\documentclass[11pt,twoside,a4paper, spanish]{report}   
\usepackage[utf8]{inputenc}
\usepackage[T1]{fontenc}
\usepackage{babel}
\usepackage[margin=3cm, showframe]{geometry}
\usepackage{url, graphicx}

\usepackage{caption}%[center]

\usepackage{multirow}   
\usepackage{gensymb}    
\usepackage{enumitem}   

\raggedbottom       

\usepackage{helvet}                 
\renewcommand{\familydefault}{\sfdefault}       

\setlength{\parindent}{0pt}         
\setlength{\parskip}{1em}               
\renewcommand{\baselinestretch}{1.5}    

\usepackage[notlot,notlof,nottoc,notindex]{tocbibind}   
\usepackage{titlesec}
\titleformat{\chapter}[display]
{\normalfont\huge\bfseries}{\chaptertitlename\ \thechapter}{20pt}{\Huge}
\titlespacing*{\chapter}{0pt}{-50pt}{40pt}

\usepackage{array}      
\usepackage{booktabs}       
\newcommand{\tabitem}{~~\llap{\textbullet}~~}

\usepackage{changepage} 
\usepackage{siunitx, makecell}
\sisetup{range-phrase=–, abbreviations=true, range-units=single, detect-all}
\DeclareSIUnit{\deg}{\degreeCelsius}
\usepackage[usestackEOL]{stackengine}

\begin{document}

\section{Introduction}

\begin{table}[htbp]
\begin{adjustwidth}{-1.5cm}{-1.5cm}
\setlength\tabcolsep{4pt}
\setstackgap{L}{2.6ex}
\footnotesize
\centering
\caption{Comparación de características entre los instrumentos actuales para baterías en el mercado}
\begin{tabular}{|l|*{5}{c|}}%
\cline{2-6}
\multicolumn{1}{c|}{} & \textbf{Cadex C7600~\cite{Cadexcompany}} & \textbf{Cadex C8000~\cite{Company}} %
& \textbf{NI PXI-4130~\cite{NationalInstruments2000}} &      \textbf{Tektronix 2380~\cite{KEITHLEYaTektronixCompany}}%
& \textbf{Maynuo M9712C~\cite{MaynuoElectronic}}\\%
\hline
\makecell[l]{Battery\\[-0.8ex] voltage range} & \SIrange{1.2}{36}{V} & \SIrange{1.2}{36}{V} & \SIrange{0}{20}{V} & \SIrange{0}{500}{V} & \SIrange{0.1}{150}{V} \\%
\hline
Discharge method & Constant current & \makecell{Constant current \\[1ex] \\ Constant power} & \makecell{Constant current \\[1ex] \\ Constant voltage} & \makecell{Constant current \\[-0.5ex] Constant voltage \\[1ex] Constant resistance \\[-0.5ex] Constant power} & \makecell{Constant current \\[-0.5ex] Constant voltage \\[1ex] Constant resistance \\[-0.5ex]Constant power} \\
\hline
\makecell[l]{Range of \\[-0.8ex] discharge current} & \SI{100}{mA}\textendash\SI{6}{A} & \SI{30}{mA}– \SI{10}{A} & \SIrange{2}{20}{mA} & \SIrange{0}{15}{A} & \SIrange{0}{6}{A} \\%
\hline
Resolution & \SI{25}{mA} & \SI{1}{mA} & \SI{100}{nA} & \SI{1}{mA} & \SI{0.01}{mA} \\%
\hline
Exactitude & 0.25\% FS & 0.25\% FS & 0.03\% FS & \Centerstack{(0.05\% FR \\+ 0.05\% FS)} & \Centerstack{0.015\% FR\\ + 0.05\% FS} \\%
\hline
\makecell[l]{Operating\\[-0.8ex] Temperature} & \SIrange{5}{35}{\deg}& \SIrange{5}{35}{\deg} & \SIrange{0}{55}{\deg} & \SIrange{0}{40}{\deg} & \SIrange{0}{40}{\deg} \\%
\hline
Display & \Centerstack{2\,x\,40-character\\ LCD} & \Centerstack{5.7'' (145mm) QVGA \\320\,x\,240 graphics\\ with backlight} & \Centerstack{No available\\ information} & Monitor Output BNC & \Centerstack{High-luminance\\ VFD screen\\ with two lines} \\%
\hline
Data ports & \Centerstack{RS-232 or USB\\ interfaces to PC} & \Centerstack{Ethernet 10/100 MB\\ for connection to PC} & \Centerstack{No available\\ information} & USB, RS-232, GPIB & USB, RS232, RS485 \\%
\hline
\end{tabular}
\end{adjustwidth}
\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 .