6

I'd like to have a breakable inlined box in order to emphasis some text. Any idea how to do that, if possible with tcolorbox?

Thanks!

enter image description here

MWE:

\documentclass[12pt]{article}
\usepackage[utf8]{inputenc}
\usepackage[T1]{fontenc} % To switch to the T1 encoding
\usepackage{lmodern} % To switch to Latin Modern
\usepackage{exscale}
\usepackage[most]{tcolorbox}

\pagestyle{empty}

\begin{document}
\noindent Base text:\\
\noindent\rule{4cm}{1pt}\\
\begin{minipage}{4cm}
  Hello I would like to have a breakable tcbox in order to have a nice text.
\end{minipage}

\vspace{1cm}
\noindent With box (no break ??):\\
\noindent\rule{4cm}{1pt}\\
\begin{minipage}{4cm}
  Hello \tcbox[enhanced,nobeforeafter,tcbox raise base,breakable,colback=red!5!white,bottom=0pt,top=0pt,right=0pt,left=0pt,
    colframe=red!75!black]{I would like to have a breakable tcbox} in order to have a nice text.
\end{minipage}

\end{document}
4
  • 1
    It won't with tcolorbox. You would need some code that marks the begin and the end and then calculates the pathes, that's not an easy task. Check tex.stackexchange.com/questions/5959/… Commented Nov 13, 2018 at 13:33
  • @Ulrike Fischer: thanks for the links, it's very interesting but I can't find how to adapt it to tcbox, partly because I don't know how to go from tikz marquers to tcbox position…
    – tobiasBora
    Commented Nov 16, 2018 at 11:22
  • 1
    @tobiasBora See this post from the tcolorbox Github page
    – mbert
    Commented Sep 28, 2023 at 13:54
  • @mbert cool trick, thanks a lot!
    – tobiasBora
    Commented Sep 28, 2023 at 14:59

1 Answer 1

2

Simply select the mode capture=minipage in the options (see page 94 of manual 4.14).

I loaded the showframe package in order to visualize the margins.

box

\documentclass[12pt]{article}
\usepackage[utf8]{inputenc}
\usepackage[T1]{fontenc} % To switch to the T1 encoding
\usepackage{lmodern} % To switch to Latin Modern
\usepackage{exscale}
\usepackage[most]{tcolorbox}
\usepackage{showframe}
\pagestyle{empty}

\begin{document}
\noindent Base text:\\
\noindent\rule{4cm}{1pt}\\
\begin{minipage}{4cm}
  Hello I would like to have a breakable tcbox in order to have a nice text.
\end{minipage}

\vspace{1cm}
\noindent With box (no break ??):\\
\noindent\rule{4cm}{1pt}\\
\begin{minipage}{4cm}
  Hello \tcbox[capture=minipage,enhanced,tcbox raise base,breakable,colback=red!5!white,bottom=0pt,top=0pt,right=0pt,left=0pt,
    colframe=red!75!black]{I would like to have a breakable tcbox} in order to have a nice text.
\end{minipage}

\end{document}
2
  • 2
    Thanks for the answer, but it's not exactly what I'm looking for, as I would like to keep the box as "inline", so in my example I'd the words "I would like" to stay,on the first line, exactly like in the first example. I just want to add a box around, that would "break" in several lines. A way to proceed would be to create three tcboxes, and set the first one with sharp right angles, the second box on the next line with all the angles sharp, and the last box on the last line and third line would have the left angles sharp. Of course this method is ugly.
    – tobiasBora
    Commented Nov 16, 2018 at 11:07
  • @tobiasBora You must therefore do as indicated by Ulrike Fischer in her commentary.
    – AndréC
    Commented Nov 16, 2018 at 11:10

You must log in to answer this question.

Not the answer you're looking for? Browse other questions tagged .