强制将标题设为单行

强制将标题设为单行

我是 LaTex 新手,正在写论文。目前,我在横向模式下遇到了表格问题。我希望我的标题在一行上。我想我必须使用 captionsetup,但我无法解决它。谢谢您的帮助。

这是表格的代码(比图中的行数少,并且用 + 代替 \pm)。

\documentclass[12pt,twoside]{report}
\usepackage[utf8]{inputenc}
\usepackage{lscape}
\usepackage[width=0.9\textwidth,labelfont=bf]{caption}
\usepackage{array} \usepackage{tabularx}

\begin{document}

\begin{landscape}
    \begin{table}[h!]
        \centering
        \caption{Elemental composition (in wt.$\%$) of the nine alloys investigated in this work}
        \renewcommand{\arraystretch}{2}
        \begin{tabularx}{0.9\hsize}[h!]{ 
           >{\raggedright\arraybackslash}p{3.9cm} 
           >{\centering\arraybackslash}X
           >{\centering\arraybackslash}X
           >{\centering\arraybackslash}X
           >{\centering\arraybackslash}X
           >{\centering\arraybackslash}X
           >{\raggedright\arraybackslash}X } 
        \hline
            & \multicolumn{6}{c}{Results (wt.$\%$)} \\
            Alloy name & Ti & Nb & Ga & Cu & O & N \\
            (Ti-45Nb)-2Ga & 53.61 + 0.72 & 43.86 + 0.73 & 1.99 + 0.07 & & 0.099 + 0.010 & 0.002 + 0.000\\
            (Ti-45Nb)-4Ga & 52.58 + 0.35 & 42.77 + 0.24 & 3.87 + 0.05 & & 0.111 + 0.008 & 0.004 + 0.001 \\
            (Ti-45Nb)-6Ga & 51.51 + 0.36 & 41.97 + 0.33 & 5.83 + 0.05 & & 0.091 + 0.015 & 0.003 + 0.001 \\
            (Ti-45Nb)-8Ga & 50.23 + 0.59 & 41.03 + 0.31 & 7.89 + 0.12 & & 0.088 + 0.004 & 0.001 + 0.000 \\
\hline
        \end{tabularx}
        \label{tab:Elemental composition of the nine alloys}
    \end{table}
\end{landscape}

\end{document}

它看起来是这样的:

在此处输入图片描述

答案1

\textwidth里面landscape是原始(窄)肖像文本宽度。您可以指定适合您的文本的更宽的长度,例如\columnwidth

\documentclass[12pt,twoside]{report}
\usepackage[utf8]{inputenc}
\usepackage{lscape}
\usepackage[width=0.9\textwidth,labelfont=bf]{caption}
\usepackage{array} \usepackage{tabularx}

\begin{document}

\begin{landscape}
    \begin{table}[h!]
        \centering
         \captionsetup{width=0.9\columnwidth,labelfont=bf}
        \caption{Elemental composition (in wt.$\%$) of the nine alloys investigated in this work}
        \renewcommand{\arraystretch}{2}
        \begin{tabularx}{0.9\hsize}[h!]{ 
           >{\raggedright\arraybackslash}p{3.9cm} 
           >{\centering\arraybackslash}X
           >{\centering\arraybackslash}X
           >{\centering\arraybackslash}X
           >{\centering\arraybackslash}X
           >{\centering\arraybackslash}X
           >{\raggedright\arraybackslash}X } 
        \hline
            & \multicolumn{6}{c}{Results (wt.$\%$)} \\
            Alloy name & Ti & Nb & Ga & Cu & O & N \\
            (Ti-45Nb)-2Ga & 53.61 + 0.72 & 43.86 + 0.73 & 1.99 + 0.07 & & 0.099 + 0.010 & 0.002 + 0.000\\
            (Ti-45Nb)-4Ga & 52.58 + 0.35 & 42.77 + 0.24 & 3.87 + 0.05 & & 0.111 + 0.008 & 0.004 + 0.001 \\
            (Ti-45Nb)-6Ga & 51.51 + 0.36 & 41.97 + 0.33 & 5.83 + 0.05 & & 0.091 + 0.015 & 0.003 + 0.001 \\
            (Ti-45Nb)-8Ga & 50.23 + 0.59 & 41.03 + 0.31 & 7.89 + 0.12 & & 0.088 + 0.004 & 0.001 + 0.000 \\
\hline
        \end{tabularx}
        \label{tab:Elemental composition of the nine alloys}
    \end{table}
\end{landscape}

\end{document}

在此处输入图片描述

答案2

只需使用与表中相同的技巧,即使用\hsize

另一方面,桌子可以轻松适应宽度。

\documentclass[12pt,twoside]{report}
\usepackage[utf8]{inputenc}
\usepackage{lscape}
\usepackage[width=0.9\textwidth,labelfont=bf]{caption}
\usepackage{array}
\usepackage{tabularx}
\usepackage{booktabs}
\usepackage{siunitx}

\begin{document}

\begin{landscape}
\begin{table}[!htp]
\centering
\captionsetup{width=0.9\hsize}

\caption{Elemental composition (in wt.$\%$) of the nine alloys investigated in this work}
\label{tab:Elemental composition of the nine alloys}

\begin{tabularx}{0.9\hsize}{ 
  >{\raggedright\arraybackslash}p{3.9cm} 
  >{\centering\arraybackslash}X
  >{\centering\arraybackslash}X
  >{\centering\arraybackslash}X
  >{\centering\arraybackslash}X
  >{\centering\arraybackslash}X
  >{\raggedright\arraybackslash}X
} 
\toprule
Alloy name & \multicolumn{6}{c}{Results (wt.$\%$)} \\
\cmidrule{2-7}
& Ti & Nb & Ga & Cu & O & N \\
\midrule
(Ti-45Nb)-2Ga & 53.61 + 0.72 & 43.86 + 0.73 & 1.99 + 0.07 & & 0.099 + 0.010 & 0.002 + 0.000 \\
\addlinespace
(Ti-45Nb)-4Ga & 52.58 + 0.35 & 42.77 + 0.24 & 3.87 + 0.05 & & 0.111 + 0.008 & 0.004 + 0.001 \\
\addlinespace
(Ti-45Nb)-6Ga & 51.51 + 0.36 & 41.97 + 0.33 & 5.83 + 0.05 & & 0.091 + 0.015 & 0.003 + 0.001 \\
\addlinespace
(Ti-45Nb)-8Ga & 50.23 + 0.59 & 41.03 + 0.31 & 7.89 + 0.12 & & 0.088 + 0.004 & 0.001 + 0.000 \\
\bottomrule
\end{tabularx}

\end{table}
\end{landscape}

\begin{table}[!htp]
\centering
\sisetup{input-signs=}
\setlength{\tabcolsep}{0pt}

\caption{Elemental composition (in wt.$\%$) of the nine alloys investigated in this work}
\label{tab:Elemental composition of the nine alloys-again}

\begin{tabular*}{0.9\textwidth}{
  @{\extracolsep{\fill}}
  l
  S[table-format=2.2{+}]
  S[table-format=2.2{+}]
  S[table-format=1.2{+}]
  S[table-format=2.2{+}] % missing data for Cu
  S[table-format=1.3{+}]
  S[table-format=1.3{+}]
  @{}
} 
\toprule
Alloy name & \multicolumn{6}{c}{Results (wt.$\%$)} \\
\cmidrule{2-7}
& {Ti} & {Nb} & {Ga} & {Cu} & {O} & {N} \\
\midrule
(Ti-45Nb)-2Ga & 53.61+ & 43.86+ & 1.99+ & & 0.099+ & 0.002+ \\
              &  0.72  &  0.73  & 0.07  & & 0.010  & 0.000  \\
\addlinespace
(Ti-45Nb)-4Ga & 52.58+ & 42.77+ & 3.87+ & & 0.111+ & 0.004+ \\
              &  0.35  &  0.24  & 0.05  & & 0.008  & 0.001  \\
\addlinespace
(Ti-45Nb)-6Ga & 51.51+ & 41.97+ & 5.83+ & & 0.091+ & 0.003+ \\
              &  0.36  &  0.33  & 0.05  & & 0.015  & 0.001  \\
\addlinespace
(Ti-45Nb)-8Ga & 50.23+ & 41.03+ & 7.89+ & & 0.088+ & 0.001+ \\
              &  0.59  &  0.31  & 0.12  & & 0.004  & 0.000  \\
\bottomrule
\end{tabular*}

\end{table}

\end{document}

在此处输入图片描述

答案3

使用包talltblr中定义的表格环境,tabularray您将不会遇到标题宽度的问题:

在此处输入图片描述

\documentclass[12pt,twoside]{report}
%\usepackage[utf8]{inputenc}
\usepackage{pdflscape}
%\usepackage[width=0.9\linewidth, labelfont=bf]{caption} % <--- if need for other floats
other floats
\usepackage{tabularray}
\UseTblrLibrary{booktabs}

\usepackage[version=4]{mhchem}
\usepackage{siunitx}

\begin{document}

\begin{landscape}
    \begin{table}[ht]
    \SetTblrStyle{caption-tag}{font=\bfseries}
    \begin{talltblr}[
        caption={Elemental composition (in wt.$\%$) 
                 of the nine alloys investigated in this work},
        label={tab:Elemental composition of the nine alloys}
                ]
                {colspec={@{} c *{6}{X[c,$]} @{}}
                }
    \toprule
    & \SetCell[c=6]{c,mode=text}  Results (wt. \%)                      \\
    \cmidrule{2-7}
Alloy name  
    & \ce{Ti}    & \ce{Nb}    & \ce{Ga}   & \ce{Cu} 
                                            & \ce{O}      & \ce{N}      \\
    \midrule
\ce{(Ti-45Nb)-2Ga} 
    & 53.61+0.72 & 43.86+0.73 & 1.99+0.07 & & 0.099+0.010 & 0.002+0.000 \\
\ce{(Ti-45Nb)-4Ga}
    & 52.58+0.35 & 42.77+0.24 & 3.87+0.05 & & 0.111+0.008 & 0.004+0.001 \\
\ce{(Ti-45Nb)-6Ga} 
    & 51.51+0.36 & 41.97+0.33 & 5.83+0.05 & & 0.091+0.015 & 0.003+0.001 \\
\ce{(Ti-45Nb)-8Ga} 
    & 50.23+0.59 & 41.03+0.31 & 7.89+0.12 & & 0.088+0.004 & 0.001+0.000 \\
    \bottomrule
    \end{talltblr}
    \end{table}
\end{landscape}

\end{document}

无关:
我擅自对您的表格设计做了一些小改动。如您所见,您的 MWE 和表格中添加了以下内容:

  • booktabs表格水平规则包(作为 `tabularray 库加载)
  • [version=4]{mhchem}化学公式包
  • 在表格的列标题和表格底部添加了规则
  • 对于这个表不需要caption包,但是对于其他浮点数可以按照@David Carlisle 答案中的建议或上面 MWE 中的注释代码行使用

答案4

一个简单的解决方案floatrow

\documentclass[12pt,twoside]{report}
\usepackage[utf8]{inputenc}
\usepackage{lscape}
\usepackage[labelfont=bf]{caption}%
\usepackage{array} \usepackage{tabularx}
\usepackage{floatrow}

\begin{document}

\begin{landscape}
    \begin{table}[h!]
        \centering
       \ttabbox[\FBwidth]{ \caption{Elemental composition (in wt.$\%$) of the nine alloys investigated in this work}\label{tab:Elemental composition of the nine alloys}}
       { \renewcommand{\arraystretch}{2}
        \begin{tabularx}{0.9\hsize}[h!]{
           >{\raggedright\arraybackslash}p{3.9cm}
           >{\centering\arraybackslash}X
           >{\centering\arraybackslash}X
           >{\centering\arraybackslash}X
           >{\centering\arraybackslash}X
           >{\centering\arraybackslash}X
           >{\raggedright\arraybackslash}X }
        \hline
            & \multicolumn{6}{c}{Results (wt.$\%$)} \\
            Alloy name & Ti & Nb & Ga & Cu & O & N \\
            (Ti-45Nb)-2Ga & 53.61 + 0.72 & 43.86 + 0.73 & 1.99 + 0.07 & & 0.099 + 0.010 & 0.002 + 0.000\\
            (Ti-45Nb)-4Ga & 52.58 + 0.35 & 42.77 + 0.24 & 3.87 + 0.05 & & 0.111 + 0.008 & 0.004 + 0.001 \\
            (Ti-45Nb)-6Ga & 51.51 + 0.36 & 41.97 + 0.33 & 5.83 + 0.05 & & 0.091 + 0.015 & 0.003 + 0.001 \\
            (Ti-45Nb)-8Ga & 50.23 + 0.59 & 41.03 + 0.31 & 7.89 + 0.12 & & 0.088 + 0.004 & 0.001 + 0.000 \\
\hline
        \end{tabularx}}

    \end{table}
\end{landscape}

\end{document}

在此处输入图片描述

相关内容