3

I make a table whose width is more than the width of the text, so the table is too right on the paper. How should I move it to center? For example:

\documentclass{article}
\usepackage{tabularray}
\usepackage{tabularx}
\begin{document}
\begin{table}
\begin{talltblr}[caption={hello}]{
        colspec={X[c]},width=3cm+\textwidth
    }
    \hline
    hello
\end{talltblr}
\end{table}
\end{document}

enter image description here

4 Answers 4

2

Similar functionality as scrextend offer package changepage. With its macro

\begin{adjustwidth}{left margin}{right margin}

or

\begin{adjustwidth*}{}{outer margin}

locally change text margins. More detail description is in package documentation. In your case your MWE should be changed to:

\documentclass{article}
\usepackage{tabularray}
\usepackage[strict]{changepage}

\usepackage{lipsum}

\begin{document}
\lipsum[66]
    \begin{table}[ht]
\begin{adjustwidth}{-15mm}{-15mm}
\begin{talltblr}[
caption = {hello},
  label = {tab:??}]{hlines, vlines, % that width of table is clearly seen
                 colspec={X[c]}
                }
    Hello world!
\end{talltblr}
\end{adjustwidth}
    \end{table}
\lipsum[66]
\end{document}

enter image description here

3
  • What's the difference between this two packages?
    – Y. zeng
    May 12, 2022 at 8:00
  • @Y.zeng, I can't say. I'm not familiar with scrextend. As I see from Raffaele Santoro answer, syntax is different. The changepage is aware if it is used on odd or even pages, enables simple extend tex area to one side (usual outer) of text area.
    – Zarko
    May 12, 2022 at 8:20
  • I see the changepage is newer than scrextend though all of those are so old. But, the newer should be better in most cases.
    – Y. zeng
    May 12, 2022 at 8:42
4

Use \centerline{material}, from your example:

\centerline{%
   \begin{talltblr}[caption={hello}]{
           colspec={X[c]},width=3cm+\textwidth
       }
       \hline
       hello
   \end{talltblr}%
}
4
  • Thanks. What package does \centerline belong to? What's the meaning of the \hss?
    – Y. zeng
    May 12, 2022 at 7:52
  • \centerline is Plain TeX macro which is defined in LaTeX kernel too. You need not any package. The \hss is TeX primitive. Because the LaTeX macro is based on TeX, then this primitive command is ready for LaTeX documents too. It is equivalent to the primitive construction \hskip 0pt plus 1fil minus 1fil.
    – wipet
    May 12, 2022 at 9:36
  • I tested and found that with and without \hss are the same. What is the reason?
    – Y. zeng
    May 12, 2022 at 13:55
  • You are right. It was my mistake. \hss are needed if plain TeX's \line macro is used. \centerline macro includes both \hss itself.
    – wipet
    May 12, 2022 at 15:12
3

Put it in a \makebox with [c]:

\documentclass{article}
\usepackage{tabularray}
\usepackage{tabularx}
\begin{document}
\begin{table}
\makebox[\textwidth][c]{\begin{talltblr}[caption={hello}]{
        colspec={X[c]},width=3cm+\textwidth
    }
    \hline
    hello
\end{talltblr}}
\end{table}
\end{document}

Note: This is only possible with contents that don't cross page borders, e.g. not with longtblr.

2

Try to modify the margins for your(s) table(s) with this code:

\documentclass{article}
\usepackage{scrextend}
\usepackage{,showframe,lipsum}% for demo only!
\begin{document}
    \lipsum[1]\\
    
    \begin{addmargin}[-1.5cm]{-1.5cm}% 1.5cm left, 1.5cm right
                
            \lipsum[2]\\
            
    \end{addmargin}
    \lipsum[1]
    \begin{addmargin}[1em]{2em}% 1em left, 2em right
        \lipsum[2]\\
        
        \lipsum[3]\\
    \end{addmargin}

    \lipsum[3]
\end{document}

You can put your table here:

        \begin{addmargin}[-1.5cm]{-1.5cm}% 1.5cm left, 1.5cm right
                    
                \lipsum[2]\\
                
        \end{addmargin}

EDIT:

\documentclass{article}
\usepackage{tabularray}
\usepackage[strict]{changepage}

\usepackage{lipsum}

\begin{document}
    \lipsum[66]
    \begin{table}[ht]
        \begin{adjustwidth}{-15mm}{-15mm}
            \begin{talltblr}[
                caption = {hello},
                label = {tab:hello}]{hlines, colspec={X[l]}
                }
                \lipsum[1-2]
            \end{talltblr}
        \end{adjustwidth}
    \end{table}\\
    See the table \ref{tab:hello}.\\
    \lipsum[66]
\end{document}

Output: enter image description here

2
  • 1
    I see there is a need to put begin{add Margin}...\end{addmargin} in \begin{table} \end{table}. What is the reason?
    – Y. zeng
    May 12, 2022 at 4:46
  • @Y.zeng See the EDIT in my answer. May 12, 2022 at 16:38

You must log in to answer this question.

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