如何减少特定单元格之间的空间并正确地使标题表居中?

如何减少特定单元格之间的空间并正确地使标题表居中?

我最近才开始使用 LaTeX,它非常棒。不过,我一般都不太会处理表格。

这是迄今为止我最好的表格创作,但仍然不完美。如您所见,标题的表格没有正确居中,而 Tektronix 的“恒流”和 Maynuo 的列之间的单元格空间太大。

在此处输入图片描述

这是我的代码,我会把所有的包都放上去以防出现问题。

\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}

我将非常感激任何帮助和改进我的表格的建议。提前致谢!

答案1

像这样?

在此处输入图片描述

编辑:raggedright列类型由 改为,修正了包 的环境centering错误使用。现在已加载选项并适用于两侧文档。adjustwidthchangepagestrict

在您的表格中,我首先删除所有多余的\multicolumn{1}{...}{....},然后使用在多行单元格中保留列格式的\multirow选项,将其减少到默认值的一半并用于表格使用环境。列类型定义也发生了变化。现在已适应列类型。=\tabcolseptabularxCtabularx

\begin{center} ... \end{center}最好使用而不是\centering,它不会在表格周围添加垂直空间。

在标题中,我删除了选项center(在包中center不存在),并在字体大小中选择\small。我还用减少了标题和表格之间的距离skip=1ex。对于单位使用包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}

您的 MWE 中的居中问题可能源自于列类型的定义C,因为最后一列需要比定义中稍宽的列宽。由于您没有使用englishbabel,LaTeX 不知道如何对英文单词进行连字符处理,因此会产生虚假居中。

答案2

我建议你将 的两个参数都设置\adjustwidth-2.5cm,而不只是第一个参数。这样会自动为你提供居中的标题。对于某些单元格中的两行和四行材料,我建议你使用tabular环境而不是\multirow指令。事实上,下面显示的代码\multirow根本没有使用任何指令。

在此处输入图片描述

\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} 

答案3

这里有一些改进,带有siunitxmakecellstackengine普通单元格。Makecell旨在允许单元格内换行。更轻量的代码:没有multirow,没有嵌套tabular。使用tabcolsep,我只在每边增加了 1.5 厘米。

\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}

在此处输入图片描述

相关内容