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)

5

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}
| improve this answer | |
  • @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 3 at 6: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.) – user194703 Jun 3 at 6:58
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}
| improve this answer | |

Your Answer

By clicking “Post Your Answer”, you agree to our terms of service, privacy policy and cookie policy

Not the answer you're looking for? Browse other questions tagged or ask your own question.