6

I am new to LaTex and I am writing my thesis. I am currently experiencing an issue with a table in landscape mode. I would like my caption to be on a single line. I guess I have to use the captionsetup but I can't solve it. Thanks for any help.

Here is the code for the table (with less lines than the one in figure and with \pm substituted by +).

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

and here is how it appears:

enter image description here

8
  • In order for others to test your code, please provide a full but minimal example instead of just a sniplet like this ,which we cannot test without adding stuff to it.
    – daleif
    Commented Dec 20, 2021 at 9:57
  • Hello, what do you mean exactly? Something like "usepackage" etc?
    – Ludovico
    Commented Dec 20, 2021 at 9:58
  • @Ludovico Welcome to TEX.SE. A minimal working example (MWE) is a compilable code that produces the (problematic) output that you are currently getting and starts with \documentclass... and ends with \end{document}. See the link for more details.
    – Imran
    Commented Dec 20, 2021 at 10:05
  • 4
    Probably you want width=0.9\linewidth not width=0.9\textwidth as \textwidth is the original portrait textwidth inside landscape Commented Dec 20, 2021 at 10:07
  • 1
    Your code isn't compilable since \pm can't be used outside of math mode.
    – leandriis
    Commented Dec 20, 2021 at 10:13

4 Answers 4

7

\textwidth inside landscape is the original (narrow) portrait text width. You can specify a wider length that fits your text eg \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}

enter image description here

3
  • But this would influence the entire document, so all the captions of all images and tables. I would need a local modification
    – Ludovico
    Commented Dec 20, 2021 at 11:09
  • @Ludovico try now :-) Commented Dec 20, 2021 at 11:22
  • Thanks! This worked well!
    – Ludovico
    Commented Dec 20, 2021 at 11:31
5

Just use the same trick as in the table, that is, use \hsize.

On the other hand, the table can easily fit the width.

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

enter image description here

3

With use of talltblr table environment defined in the tabularray package you will not have problems with caption width:

enter image description here

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

Off-topic:
I took a liberty and made some small changes in your table design. As you can see, to your MWE and table were added:

  • booktabs package (loaded as `tabularray library) for horizontal rules in table
  • [version=4]{mhchem} package for chemistry formulae
  • to table are added rules at column headers and at table bottom
  • for this table is not needed caption package, however for other floats can be used as is suggested in @David Carlisle answer or in commented code line in above MWE
2

A simple solution with 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}

enter image description here

You must log in to answer this question.

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