2

The following caption does not look centered properly (but I still want the table to span over the full text width so that the table does not enter within the right margin).

\documentclass{book}
\usepackage{caption}
\usepackage{tabularx}
\begin{document}
\begin{table}[h]
\setlength{\tabcolsep}{10pt}
\centering
\renewcommand{\arraystretch}{1.6}
\begin{tabularx}{\textwidth}{c|c|c|c|c|}
\multicolumn{1}{c}{} & \multicolumn{1}{c}{$s$} & \multicolumn{1}{c}{$r$} & \multicolumn{1}{c}{$t$} & \multicolumn{1}{c}{$u$} \\
\cline{2-5}
{$s$} & $1234567890$ & $1234567890$ & $1234567890$ & $1234567890$ \\
\cline{2-5}
{$r$} & $1234567890$ & $1234567890$ & $1234567890$ & $1234567890$ \\
\cline{2-5}
{$t$} & $1234567890$ & $1234567890$ & $1234567890$ & $1234567890$ \\
\cline{2-5}
{$u$} & $1234567890$ & $1234567890$ & $1234567890$ & $1234567890$ \\
\cline{2-5}
\end{tabularx}
\captionsetup{justification=centering}
\caption{Parametrised glue matrix for any gorge constraint}
\end{table}
\end{document}
1
  • 2
    don't use tabularx like this! \begin{tabularx}{\textwidth}{c|c|c|c|c|} without an X column tabularx has no way to achieve the stated \textwidth Commented Sep 24, 2016 at 10:47

2 Answers 2

2

Probably you like to obtain something like this:

enter image description here

Your caption is centered regarding text width, however position of table looks as it is shifted left. This is consequence of use tabularx (see David Carlisle comment above). By use of tabular instead tabularx you will obtain above image of table:

\documentclass{book}
\usepackage{caption}
\usepackage{array}

\usepackage{showframe}
\renewcommand*\ShowFrameColor{\color{red}}

\begin{document}
\begin{table}[h]
\setlength{\tabcolsep}{10pt}
\centering
\renewcommand{\arraystretch}{1.6}
\begin{tabular}{>{$}c<{$}|*{4}{>{$}c<{$}|}}
\multicolumn{1}{c}{} 
  & \multicolumn{1}{c}{$s$} 
               & \multicolumn{1}{c}{$r$} 
                            & \multicolumn{1}{c}{$t$} 
                                         & \multicolumn{1}{c}{$u$}\\
\cline{2-5}
s & 1234567890 & 1234567890 & 1234567890 & 1234567890 \\
\cline{2-5}
r & 1234567890 & 1234567890 & 1234567890 & 1234567890 \\
\cline{2-5}
t & 1234567890 & 1234567890 & 1234567890 & 1234567890 \\
\cline{2-5}
u & 1234567890 & 1234567890 & 1234567890 & 1234567890 \\
\cline{2-5}
\end{tabular}
\captionsetup{justification=centering}
\caption{Parametrised glue matrix for any gorge constraint}
\end{table}
\end{document}

As you can see, in above MWE I slightly optimize your code in MWE.

1
  • @Mico, yes. I forgot to add math mode to this column. I will correct this.
    – Zarko
    Commented Sep 24, 2016 at 13:25
1

To use a tabularx environment with a pre-set width (here: \textwidth), you must use the X column type -- either directly or in some suitably modified form. In the example below, I define C as a centered version of X and use it for 4 of the 5 columns; only the first column is assigned type c.

enter image description here

\documentclass{book}
\usepackage{caption,tabularx,ragged2e}
\newcolumntype{C}{>{\Centering\arraybackslash}X}   % centered 'X' column
\newcolumntype{D}{>{$}c<{$}}       % automatic math-mode centered column
\newcommand\mc[1]{\multicolumn{1}{@{}D@{}}{#1}}   % handy shortcut macro

\begin{document}

\begin{table}[h]
\captionsetup{justification=Centering}
\setlength{\tabcolsep}{10pt}
\renewcommand{\arraystretch}{1.6}
\begin{tabularx}{\textwidth}{@{} D|C|C|C|C| }
\mc{} & \mc{s} & \mc{r} & \mc{t} & \mc{u} \\
\cline{2-5}
s & $1234567890$ & $1234567890$ & $1234567890$ & $1234567890$ \\
\cline{2-5}
r & $1234567890$ & $1234567890$ & $1234567890$ & $1234567890$ \\
\cline{2-5}
t & $1234567890$ & $1234567890$ & $1234567890$ & $1234567890$ \\
\cline{2-5}
u & $1234567890$ & $1234567890$ & $1234567890$ & $1234567890$ \\
\cline{2-5}
\end{tabularx}
\caption{Parametrised glue matrix for any gorge constraint}
\end{table}
\end{document}

You must log in to answer this question.

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