1

Given the following table with the column type C defined so that it has (small) fixed width and supposedly centered text, how can I make it so that the text is actually centered? None of the cell contents will have a length greater than 3 digits with a decimal point.

Using \setlength\tabcolsep{} doesn't work and setting the column type to c has the columns too wide, though p looks essentially identical as the cells are too small to have actually centered text. Using @{} removes all padding along the left side of the cell.

\newcolumntype{C}[1]{>{\centering\arraybackslash}m{#1}}

\begin{table}[]
    \centering
    \begin{tabularx}{\textwidth}{|r||C{.31cm}|C{.31cm}|C{.31cm}|C{.31cm}|C{.31cm}|C{.31cm}|C{.31cm}||}
    
    \cline{1-8}
        \small ---- & \footnotesize0.9 & \footnotesize0.92 & \footnotesize0.99 & \footnotesize1.0 & \footnotesize\textbf{***} & \footnotesize\textbf{***} & \footnotesize\textbf{***}\\
    \cline{1-8}
    
    \end{tabularx}
\end{table}

enter image description here

7
  • Welcome to TeX SX! You didn't set any value for \tabcolsep?
    – Bernard
    Aug 12, 2021 at 17:02
  • Why would you want to use an m column identifier for something that is not paragraph based? Aug 12, 2021 at 17:18
  • Bernard, I tried a few different values for \tabcolsep but none solved the centering issue. Steven, a p would work just as well, but the issue persists.
    – Alex
    Aug 12, 2021 at 17:27
  • I hadn't noticed that you specified a width for your X type columns. You don't have to: the width of cells is determined by the package, on the basis of the total width.
    – Bernard
    Aug 12, 2021 at 17:34
  • I need all the cells/columns to be uniform in width.
    – Alex
    Aug 12, 2021 at 17:37

3 Answers 3

2

What about one of the following two suggestions?

enter image description here

\documentclass{article}
\usepackage{array}
\begin{document}

\newcolumntype{C}[1]{>{\centering\arraybackslash}m{#1}}

\begin{table}
    \centering
    \setlength{\tabcolsep}{0pt}
    \begin{tabular}{|@{\hspace{6pt}}r@{\hspace{6pt}}||*{7}{>{\footnotesize}C{\dimexpr.31cm+12pt}|}|}
    \cline{1-8}
        \small --- & 0.9 & 0.92 & 0.99 & 1.0 & \textbf{***} &  \textbf{***} & \textbf{***}\\
    \cline{1-8}
    \end{tabular}
\end{table}

\end{document}

\documentclass{article}
\usepackage{array}
\usepackage{calc}
\newlength{\mywidth}

\begin{document}
\begin{table}
    \centering
    \setlength{\mywidth}{\widthof{\footnotesize 0.99}}
    \begin{tabular}{|r||*{7}{>{\footnotesize}wc{\mywidth}|}|}
    \cline{1-8}
        \small --- & 0.9 & 0.92 & 0.99 & 1.0 & \textbf{***} &  \textbf{***} & \textbf{***}\\
    \cline{1-8}
    \end{tabular}
\end{table}

\end{document}
1
  • That first one worked great, thank you!!
    – Alex
    Aug 12, 2021 at 18:19
2

I suppose this is what you want?

\documentclass{article}

\usepackage{array, tabularx}
\setlength{\extrarowheight}{2pt}
\renewcommand{\tabularxcolumn}[1]{>{\small}m{#1}}
\newcolumntype{C}{>{\centering\arraybackslash}X}

\begin{document}

\begin{table}
    \centering
    \begin{tabularx}{\textwidth}{|r||*{7}{C|}|}
    \hline%\cline{1-8}
        \small --- & \footnotesize 0.9 & \footnotesize 0.92 & \footnotesize 0.99 & \footnotesize 1.0 & \footnotesize\textbf{***} & \footnotesize\textbf{***} & \footnotesize\textbf{***}\\
    \hline%\cline{1-8}
    \end{tabularx}
\end{table}

\end{document} 

enter image description here

0

An alternative solution with tabularray package:

\documentclass{article}

\usepackage{tabularray}

\begin{document}

\begin{table}
  \centering
  \begin{tblr}{
    width = 0.55\textwidth,
    colspec={|r||X[c]|X[c]|X[c]|X[c]|X[c]|X[c]|X[c]||},
    column{1} = {font=\small},
    column{2-5} = {colsep=3pt,font=\footnotesize},
    column{6-8} = {colsep=3pt,font=\footnotesize\bfseries},
  }
    \cline{1-8}
    --- & 0.9 & 0.92 & 0.99 & 1.0 & *** & *** & *** \\
    \cline{1-8}
  \end{tblr}
\end{table}

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