I am trying to reproduce, with minor differences, the caption style that I have seen in the microtype documentation:
I am using a the tufte-book class with the [openany]
parameter so the margin is always on the right side of the page. An example table looks like this:
My approach is to use tcolorbox
to frame my figure and tables (since I am using the package elsewhere and like its flexibility), draw an horizontal line from the box to margin and complete the line inside the caption by modifying its definition.
With my poor programming skills knowledge I hacked my way up to something that may be close to the result I want, although the code would most likely hurt the eyes of any decent LaTeX programmer.
I modified the caption definition to remove the colon, introduce a line break, draw line as long as the caption width (but no longer that \linewidth
) and fiddle with \parskip
to adjust vertical spacing. Here is the code:
\newlength{\captlength}%will contain caption length
\makeatletter
%%% below is unchanged code from tufte definitions
\long\def\@caption#1[#2]#3{%
\par%
\addcontentsline{\csname ext@#1\endcsname}{#1}%
{\protect\numberline{\csname the#1\endcsname}{\ignorespaces #2}}%
\begingroup%
\@parboxrestore%
\if@minipage%
\@setminipage%
\fi%
\@tufte@caption@font\@tufte@caption@justification%
%%%% and below is the modified code
\settowidth{\captlength}{#3}%capture caption length
\ifdim \captlength > \linewidth%make sure \captlength is not greater than
\linewidth
\setlength{\captlength}{\linewidth}
\fi %
\noindent\csname fnum@#1\endcsname\par\setlength{\parskip}
{-1ex}\noindent\color{gray}\raisebox{0.65ex}{\rule{\captlength}
{0.4pt}}\par\noindent\color{black}#3\par%add line breaks, gray rule and adjust
vertical spacing
\endgroup}
\makeatother
Now making a table with tcolorbox
as frame:
\begin{table}[ht]
\centering
\begin{tcolorbox}[enhanced, remember, hbox, tcbox width=auto limited,
colback=white,arc=1pt,boxrule=0.4pt,colframe=gray]
\caption{A table with a caption.}
\begin{tabular}{lll}
first col. & second one & last one \\
filling this & and this too & some more text
\end{tabular}
\end{tcolorbox}
\end{table}
Now I would need to draw the connecting horizontal line from the right edge of the box with a vertical offset so it can be at the same level with the caption rule using the tikz implementation of tcolorbox. I figured I would benefit from the tikzpagenodes
package as well to get the margin node definition.
The problem is that tikz is very foreign to me, as you can see from the lame attempt below:
\begin{table}[ht]
\centering
\begin{tcolorbox}[enhanced, remember, hbox, tcbox width=auto limited,
colback=white,arc=1pt,boxrule=0.4pt,colframe=gray,
overlay={\draw[gray,line width=0.4pt](frame.north east) edge[->] (current page marginpar area.west);}]
\caption{A table with a caption.}
\begin{tabular}{lll}
first col. & second one & last one \\
filling this & and this too & some more text
\end{tabular}
\end{tcolorbox}
\end{table}
I would appreciate any help. Thanks in advance! Here is the full code:
% !TEX program = xelatex
\documentclass[openany, justified]{tufte-book}
\usepackage{tikzpagenodes,graphicx}
\usepackage[most]{tcolorbox}
\newlength{\captlength}%will contain caption length
\makeatletter
\long\def\@caption#1[#2]#3{%
\par%
\addcontentsline{\csname ext@#1\endcsname}{#1}%
{\protect\numberline{\csname the#1\endcsname}{\ignorespaces #2}}%
\begingroup%
\@parboxrestore%
\if@minipage%
\@setminipage%
\fi%
\@tufte@caption@font\@tufte@caption@justification%
\settowidth{\captlength}{#3}%capture caption length
\ifdim \captlength > \linewidth%make sure \captlength is not greater than
\linewidth
\setlength{\captlength}{\linewidth}
\fi %
\noindent\csname fnum@#1\endcsname\par\setlength{\parskip}
{-1ex}\noindent\color{gray}\raisebox{0.65ex}{\rule{\captlength}
{0.4pt}}\par\noindent\color{black}#3\par%add line breaks, gray rule and adjust
vertical spacing
\endgroup}
\makeatother
\begin{document}
\begin{table}[ht]
\centering
\begin{tcolorbox}[enhanced, remember, hbox, tcbox width=auto limited,
colback=white,arc=1pt,boxrule=0.4pt,colframe=gray,overlay={\draw[gray,line
width=0.4pt](frame.north east) edge[->] (current page marginpar area.west);}]
\caption{A table with a caption.}
\begin{tabular}{lll}
first col. & second one & last one \\
filling this & and this too & some more text
\end{tabular}
\end{tcolorbox}
\end{table}
\end{document}
(frame.north east) -- (frame.north -| current page marginpar area.west)
.