# How can I make disappear the indent of my caption in Tufte book style?

I've some troubles with my caption definition in my Tufte book style document. The caption work perfectly fine for marginfigure environments while it indent the figure label for figure, margintable and table environments. You can see on the pictures below framed in green what I want as an indent (i.e. nothing) for my caption style and in red what I don't want.

You can find my caption definition here in my minimal document code under the CAPTION STYLE comment divider:

\documentclass[justified,notoc,numbers]{tufte-handout}
\usepackage{graphicx}
\usepackage{fancyhdr}
\usepackage{xcolor}

\setkeys{Gin}{width=\linewidth,totalheight=\textheight,keepaspectratio}
\graphicspath{{graphics/}}

%=======================================================
%                      FOR DEBUG
%=======================================================
\usepackage{lipsum}

%=======================================================
%                      FONT STYLE
%=======================================================
\renewcommand{\rmdefault}{ptm}

%=======================================================
%                       COLORS
%=======================================================
\definecolor{myColor}{rgb}{0.0, 0.5, 1.0}

%=======================================================
%                   CAPTION STYLE
%=======================================================
\makeatletter
\long\def\@caption#1[#2]#3{%
%
{\protect\numberline{\csname the#1\endcsname}{\ignorespaces #2}}%
\begingroup%
\@parboxrestore%
\if@minipage%
\@setminipage%
\fi%
\@tufte@caption@font\@tufte@caption@justification%
\colorbox{myColor}{\color{white}\csname fnum@#1\endcsname:} \ignorespaces#3\par%
\endgroup}
\makeatother

%=======================================================
%                       GEOMETRY
%=======================================================
\geometry{
left=15mm,                    % left margin
textwidth=140mm,              % main text block
marginparsep=7mm,             % gutter between main text block and margin notes
marginparwidth=50mm,          % width of margin notes
bottom = 1.5cm,
top = 1.7cm
}

%=======================================================
%=======================================================
\pagestyle{fancy}{
\fancyhf{}
\rfoot{Page \thepage}

}

%=======================================================
%                       DOCUMENT
%=======================================================
\begin{document}
\begin{marginfigure}
\includegraphics{example-image-a}
\caption{This is a well indent caption as you can see with a multi line caption it is well justified.}
\end{marginfigure}

\begin{margintable}[2cm]
\centering
\begin{tabular}{c|c}
1 & 2 \\
3 & 4
\end{tabular}

\caption{This is \textbf{NOT} a well indent caption as you can see with a multi line caption it is not well justified.}
\end{margintable}
\vspace{9cm} %To make it clear
\begin{figure}
\centering
\includegraphics{example-image-b}
\caption{Once again, this is \textbf{NOT} a well indent caption as you can see with a multi line caption it is not well justified.}
\end{figure}

\begin{table}[!ht]
\centering
\begin{tabular}{c|c}
1 & 2\\
3 & 4
\end{tabular}
\caption{Once again, this is \textbf{NOT} a well indent caption as you can see with a multi line caption it is not well justified.}
\end{table}

\end{document}


I'm not really familiar with the \def command but I tried my best to get what I wanted as caption style. Does any of you know how to applied this style without any further indent for all my figure and table environments? What seems weird to me is that the style is well applied for all environments but spacings are still wildly added to some. I know that Tufte book captions' are special so I need to use \@tufte@caption to access their style but should I perform that in other places to access the other environments caption styles too?

I use pdfLaTex version 2019 as a compiler.

Thanks for your help and sorry for my english :D.

The indent is caused by \JustifyingParindent.

In marginfigure and margintable environments, the caption is printed with setting justified and \@tufte@margin@par. This makes \JustifyingParindent has value 0.5pc.

Note that in marginfigure and margintable environments, the \caption does not automatically start a new paragraph. Therefore, in your example, there is no indent before caption of marginfigure, but there is an indent before caption of margintable (the empty line before \caption starts a new paragraph).

% Paragraph indentation and separation for marginal text
\newcommand{\@tufte@margin@par}{%
\setlength{\RaggedRightParindent}{0.5pc}%
\setlength{\JustifyingParindent}{0.5pt}%
\setlength{\parindent}{0.5pc}%
\setlength{\parskip}{0pt}%
}


In figure and table environments, the caption is printed with setting justified, which sets \JustifyingParindent to value 1.0pc.

% Paragraph indentation and separation for normal text
\newcommand{\@tufte@reset@par}{%
\setlength{\RaggedRightParindent}{1.0pc}%
\setlength{\JustifyingParindent}{1.0pc}%
\setlength{\parindent}{1pc}%
\setlength{\parskip}{0pt}%
}
\@tufte@reset@par


To cancel the indent before \caption in both cases, it is sufficient to set \JustifyingParindent to zero. The following lines do the job:

\setlength{\JustifyingParindent}{0pt}
\makeatletter
\renewcommand{\@tufte@margin@par}{%
\setlength{\RaggedRightParindent}{0.5pc}%
\setlength{\JustifyingParindent}{0pc}%
\setlength{\parindent}{0.5pc}%
\setlength{\parskip}{0pt}%
}
\makeatother


PS: pc stands for "pica", 1pc = 12pt.