简体   繁体   中英

Centering only header of LaTeX table

I'd like to center just the header, but not the body of particular columns in a table. For example:

\begin{table}[!t]
\centering
\caption{
\bf{My table}}
\begin{tabular}{l|c|}
...
\end{tabular}
\end{table}

will make a left-aligned column, and a center-aligned column. I'd like the headers to all be centered, but the body of the table to actually be left aligned. If the entries in each column are wide, having left or right aligned content without centering the header looks strange (it leaves lots of whitespace in the header).

Second, is there a way to force a table to be on its own page in LaTeX? Or any figure for that matter?

Define the headings using

\multicolumn{1}{c}{Heading}

Feel free to stick leading and trailing | s around the c as needed.

In order to put a table (or any float) on its own page, use the p argument for location:

\begin{table}[p]
  ...

It will then appear at the end of the chapter/section, or when you issue a \\clearpage or \\cleardoublepage .

Use the caption package

\usepackage{caption} 
\captionsetup[table]{skip=6pt}    

or

\captionsetup[table]{aboveskip=6pt}
\captionsetup[table]{belowskip=6pt}

add in the preamble

\begin{table}[!t]
\centering
\caption{\bfseries{My table}}
\begin{tabular}{l|c|}
...
\end{tabular}
\end{table}

The technical post webpages of this site follow the CC BY-SA 4.0 protocol. If you need to reprint, please indicate the site URL or the original address.Any question please contact:yoyou2525@163.com.

 
粤ICP备18138465号  © 2020-2024 STACKOOM.COM