5

MWE:

! pdflatex
\documentclass[multi=tcolorbox,crop]{standalone}
\usepackage{tcolorbox}
\usepackage{lipsum}

\begin{document}

\begin{tcolorbox}
\lipsum[1]  
\end{tcolorbox}

\begin{tcolorbox}
\lipsum[1-2]  
\end{tcolorbox}

\end{document}

I just want to get a cropped figure in each page with a simple method.(no to use preview wrap every tcolorbox)

user26992
  • 93
  • 3

2 Answers2

7

Not exactly a solution, but it works.

\documentclass[multi=wrapper,crop]{standalone}
\usepackage{tcolorbox}
\usepackage{lipsum}

\newenvironment{wrapper}{}{}

\begin{document}

\begin{wrapper}
\begin{tcolorbox}
\lipsum[1]  
\end{tcolorbox}
\end{wrapper}

\begin{wrapper}
\begin{tcolorbox}
\lipsum[1-2]  
\end{tcolorbox}
\end{wrapper}

\end{document}
John Kormylo
  • 79,712
  • 3
  • 50
  • 120
6

Welcome! Here is an alternative way to make each tcolorbox as separate page. It does not use the standalone class, though.

\documentclass{article}
\usepackage[active,tightpage]{preview}
\usepackage{tcolorbox}

\usepackage{lipsum}
\tcbset{before=\begin{preview},after=\end{preview}}
\begin{document}

\begin{tcolorbox}
\lipsum[1]  
\end{tcolorbox}

\begin{tcolorbox}
\lipsum[1-2]  
\end{tcolorbox}

\end{document}

enter image description here

The trick is to automatically wrap the tcolorbox in a preview environment via

 \tcbset{before=\begin{preview},after=\end{preview}}

This trick may be combined with John Kormylo's nice answer to get

\documentclass[multi=wrapper,crop]{standalone}
\usepackage{tcolorbox}
\usepackage{lipsum}

\newenvironment{wrapper}{}{}
\tcbset{before=\begin{wrapper},after=\end{wrapper}}

\begin{document}

\begin{wrapper}
\begin{tcolorbox}
\lipsum[1]  
\end{tcolorbox}
\end{wrapper}

\begin{wrapper}
\begin{tcolorbox}
\lipsum[1-2]  
\end{tcolorbox}
\end{wrapper}

\end{document}
  • @John Kormylo @Schrödinger's-cat Many Thanks! I prefer the trick using article documentclass. It's clear and simple. But what confused me is why standalone class can not directly using the option [multi=tcolorbox]. It push the user to redefine a new nonsense enviorment. – user26992 Jun 03 '20 at 06:51
  • 1
    @user26992 It has to do with the saveboxes that are created, and is not specific to tcolorbox. If you consider \documentclass[tikz,border=3mm]{standalone} \newsavebox\mybox \begin{document} \savebox\mybox{\tikz{\node{boom};}} \tikz{\node{boom};} \end{document}, you get the same effect, and if you comment out the \savebox it runs through. (I am not claiming that this cannot be fixed somehow.) –  Jun 03 '20 at 06:58
  • In the last piece of code, the manually added \begin{wrapper} and \end{wrapper} calls should be removed. – frougon Aug 11 '21 at 12:54