[Tex/LaTex] How to put the label in a table’s column
labelstables
How to put the label in a table's column, just like this picture.
When I put \caption{aaa} in a column, the document cannot be compiled.
Best Answer
The following setup provides a way to insert a \tabularcaption{<cols>}{<colspec>}{<caption>}. It uses \multicolumn{<cols>}{<colspec>}{<stuff>} to insert the appropriate content, formatted the way you specify it using the caption package:
\documentclass{article}
\usepackage{caption}
\makeatletter
\newcommand{\tabularcaption}[3]{%
\multicolumn{#1}{#2}{%
\refstepcounter{table}% Step the table counter
\captionfont% Set the caption font
{\captionlabelfont\tablename\ \thetable}% Set the caption label
\caption@lsep% Set the caption separation
{\captiontextfont #3}% Set the caption text
\addcontentsline{lot}{table}{\protect\numberline{\thetable}#3}% Add caption to LoT
}%
}
\makeatother
% Whatever formatting you need for the captions
\captionsetup{%
font = sl,
labelfont = bf,
textfont = it
}
\begin{document}
\listoftables
\begin{table}
\centering
\begin{tabular}{ | *{7}{l|} }
\hline
\tabularcaption{7}{|l|}{A table} \\
\hline
A & B & C & D & E & F & G \\
\hline
1 & 2 & 3 & 4 & 5 & 6 & 7 \\
One & Two & Three & Four & Five & Six & Seven \\
\hline
\end{tabular}
\end{table}
\end{document}
Ideally one would like to just use something like \tabularcaption{<caption>}, but you'd need the flexibility to adjust the caption layout based on the content of the tabular. As such, the first two arguments are mandatory, requiring you to specify both the number of columns the caption should span, as well as the column specification/layout.
You can make it as ugly as you want by redefining the itemize lists. The labels are defined in a series of commands \labelitemi...\labelitemiv, which you can redefine.
\documentclass{article}
\begin{document}
\renewcommand\labelitemi{\textbullet\textbullet \bfseries and other ugly stuff}
\renewcommand\labelitemii{\normalfont\bfseries \textendash more ugly stuff}
\renewcommand\labelitemiii{\textasteriskcentered}
\renewcommand\labelitemiv{\textperiodcentered}
\begin{itemize}
\item First
\item second
\begin{itemize}
\item Ugly stuff.
\end{itemize}
\end{itemize}
\end{document}
This will produce:
More fancy styling is possible via redefining the makelabel command and a suitable list environment as shown in the MWE below.
\documentclass{article}
\usepackage{lipsum}
\begin{document}
\renewcommand\labelitemi{\textbullet\textbullet \bfseries and other ugly stuff}
\renewcommand\labelitemii{\normalfont\bfseries \textendash more ugly stuff}
\renewcommand\labelitemiii{\textasteriskcentered}
\renewcommand\labelitemiv{\textperiodcentered}
\lipsum[1]
\makeatletter
\def\newitemizedenvironment#1#2{
\expandafter\def\csname#1\endcsname{%
\ifnum \@itemdepth >\thr@@\@toodeep\else
\advance\@itemdepth\@ne
\edef\@itemitem{labelitem\romannumeral\the\@itemdepth}%
\expandafter
\list
\csname\@itemitem\endcsname
{\def\makelabel####1{\hspace*{150pt}\hss\llap{####1}}}%
\fi}
\expandafter\let\csname end#1\endcsname=\endlist
}
\makeatother
\newitemizedenvironment{ugly}{}
\begin{ugly}
\item First
\item second
\end{ugly}
\end{document}
Best Answer
The following setup provides a way to insert a
\tabularcaption{<cols>}{<colspec>}{<caption>}
. It uses\multicolumn{<cols>}{<colspec>}{<stuff>}
to insert the appropriate content, formatted the way you specify it using thecaption
package:Ideally one would like to just use something like
\tabularcaption{<caption>}
, but you'd need the flexibility to adjust the caption layout based on the content of thetabular
. As such, the first two arguments are mandatory, requiring you to specify both the number of columns the caption should span, as well as the column specification/layout.