T-F-S / tcolorbox

A LaTeX package to create highly customizable colored boxes.
http://www.ctan.org/pkg/tcolorbox
LaTeX Project Public License v1.3c
213 stars 15 forks source link

Adjust `blend into=figures` ToF entry indentation using `tocloft` `cftsetindents` #238

Closed mangkoran closed 9 months ago

mangkoran commented 1 year ago

First of all, thank you for creating such great package. I am pretty new with Latex and tcolorbox has made it much easier to create such beautiful boxes!

I have a question regarding the interaction of blend into. I use tocloft package to adjust the indentation of Table of Figures using its cftsetindents. However, it seems figures of tcolorbox is not affected by it.

image

As you can see, there are several entries that is indented inside a bit. Those are tcolorbox's InputListing using blend into=figures that is not affected by cftsetindents.

Below is the code I use to adjust the indentation of ToF entries.

\usepackage[titles]{tocloft}
\cftsetindents{figure}{0em}{2.75em}
\cftsetindents{table}{0em}{2.75em}
muzimuzhi commented 1 year ago

However, it seems figures of tcolorbox is not affected by it.

That's because tcolorbox sets list type=tcolorbox initially, which will result in line

\contentsline {tcolorbox}{...}{1}{}%

in .lof file if blend into=figures is set. Since \contentsline{xxx} expands to \l@xxx, the style of tcolorbox list-of entries is controlled by \l@tcolorbox by default. But what \cftsetindents{figure}{0em}{2.75em} from tocloft altered is \l@figure.

Setting list type=figure does the trick.

\documentclass{article}
\usepackage{tcolorbox}

\usepackage[titles]{tocloft}
\cftsetindents{figure}{0em}{2.75em}
\cftsetindents{table}{0em}{2.75em}

% list type=tcolorbox (default), uses \l@tcolorbox
\newtcolorbox[blend into=figures]{myfigure}[1][]{
  float=!h, capture=hbox, every float=\centering, #1
}

% list type=figure, uses \l@figure, which is influenced by tocloft
\newtcolorbox[blend into=figures, list type=figure]{myfigure2}[1][]{
  float=!h, capture=hbox, every float=\centering, #1
}

\begin{document}
\listoffigures

\begin{myfigure}[title=Env setting \texttt{list type=tcolorbox}]
  content content content content
\end{myfigure}

\begin{myfigure2}[title=Env setting \texttt{list type=figure}]
  content content content content
\end{myfigure2}

\begin{figure}[!h]
  \centering
  figure content
  \caption{normal \texttt{figure} caption}
\end{figure}
\end{document}
image
muzimuzhi commented 1 year ago

Perhaps blend into could set corresponding list type automatically. https://github.com/T-F-S/tcolorbox/blob/6d98db4263c612279cca47efde22d1ef8404e573/tex/latex/tcolorbox/tcolorbox.sty#L2142-L2145

mangkoran commented 1 year ago

@muzimuzhi I can confirm that your solution works perfectly. Thank you very much!

However, I am agree with your suggestion as user would think that blend into will blend tcolorbox into figure list, which include how they appear in ToF.

Looking for more response/opinion regarding this. For the time being, I left the issue opened.

muzimuzhi commented 1 year ago

Perhaps blend into could set corresponding list type automatically.

For blend into=listings, list type=lstlisting (corresponds to \l@lstlisting) is the needed setting.

Late update:

\tcbset{
  new/.cd,
  blend into/figures/.append style={list type=figure},
  blend into/tables/.append style={list type=table},
  blend into/listings/.append style={list type=lstlisting}
}
T-F-S commented 1 year ago

I see a certain (small) danger that existing user code may be affected by such changes and may need adaption.

But, I agree that blend into should act as far as possible as the name suggests. Therefore, setting the list type automatically is very reasonable for me and I will make these changes for the next version. Thank you for your proposals.

mangkoran commented 1 year ago

I see a certain (small) danger that existing user code may be affected by such changes and may need adaption.

Well, only for advanced users that know this behavior. We could put breaking change notice in the commit/release.

T-F-S commented 9 months ago

Done with https://github.com/T-F-S/tcolorbox/releases/tag/v6.1.0