12

I have this table:

\usepackage{array}
\newcolumntype{x}[1]{>{\centering\arraybackslash\hspace{0pt}}p{#1}}

\begin{table}[ht]\footnotesize
\centering
\begin{tabular*}{0.95\textwidth }{@{\extracolsep{\fill}}|llllllllllllllll|x{0.15\textwidth}|}
\hline
\multicolumn{16}{|c|}{Small text} & Long text \\ \hline 
1 & 5 & 6 & 7 & 8 & 9 & 10 & 11 & 12 & 13 & 16 & 19 & 20 & 21 & 22 & 23 & 0.9636149 \\ \hline 
\end{tabular*}
\caption{Caption}
\label{tab:Example}
\end{table}

How to center "Small text"?

6
  • I can't compile your example. What table-extending packages are you using? Nov 7, 2010 at 19:38
  • Sorry, I haven't included my custom column definition. Now it should compile.
    – pixel
    Nov 7, 2010 at 19:45
  • Works for me, sort of. With the standard article class the lines don't extend all the way across, because the table is too wide for the \textwidth. If I do \usepackage[letterpaper]{geometry} which shortens the margins a bit, the lines extend all the way across. Either way, though, "small text" is centered across the first 16 columns. Can you post a picture of what you're seeing? Nov 7, 2010 at 19:54
  • 1
    @Matthew: I think the important word here is vertical. Think of ”long text” as something that has multiple lines. Then “small text” is aligned at the top.
    – Caramdir
    Nov 7, 2010 at 20:20
  • 1
    Ah. I might have realized that if "long text" had actually been long text. :) Nov 7, 2010 at 21:21

2 Answers 2

10

Change the p to m in your definition of the x column type:

\newcolumntype{x}[1]{>{\centering\arraybackslash\hspace{0pt}}m{#1}}

Full example:

\documentclass{article}
\usepackage{array}
\newcolumntype{x}[1]{>{\centering\arraybackslash\hspace{0pt}}m{#1}}
\begin{document}

\begin{table}[ht]\footnotesize
\centering
\begin{tabular*}{0.95\textwidth }{@{\extracolsep{\fill}}|llllllllllllllll|x{0.15\textwidth}|}
\hline
\multicolumn{16}{|c|}{Small text} & Long long long long long text \\ \hline 
1 & 5 & 6 & 7 & 8 & 9 & 10 & 11 & 12 & 13 & 16 & 19 & 20 & 21 & 22 & 23 & 0.9636149 \\ \hline 
\end{tabular*}
\caption{Caption}
\label{tab:Example}
\end{table}
\end{document}
1
  • How one would redefine \newcolumntype above to vertically align to the top of the cells? Jan 9, 2022 at 23:57
0
\documentclass{article}
\usepackage{graphicx}% http://ctan.org/pkg/graphicx
\usepackage{array}% http://ctan.org/pkg/array
\usepackage{amsmath}
\begin{document}

\begin{table}[h!]
  \centering
  \begin{tabular}{ | c | m{5cm} | m{5cm} | }
    \hline
    11111111 & 2222222 & 33333333 \\ \hline
    \begin{minipage}{.3\textwidth}
      \includegraphics[width=\linewidth]{example-image-a.png}
    \end{minipage}
    &
    \begin{equation*}
    \dfrac{12!-x^2}{9x^3-99}
    \end{equation*}
    & 
      \begin{itemize}
        \item item111
        \item item2222222
        \item text text text
        \item Double-click here to open the full log. \ldots
      \end{itemize}
    \\ \hline
  \end{tabular}
  \caption{Your caption}
  \label{Your label}
\end{table}

\end{document}

You must log in to answer this question.

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