Here is a command I have:


What it does is boxing and numbering a text. However I for the box to break nicely across lines. In command \fbox{text} the text may stick out of the margins if the line is full. However I want to write a conditional for this case. Such as:

until text finished
after every word: 
   if there is \linebreak:
       end \fbox
       continue text with \fbox

enter image description here enter image description here

In above I added Images!

%%%%%%%%%%%%%%%%%% %%%%%%%%%%%%%%%%%%

I used multiline colored box but as I said, since sentences are small it doesn’t look that nice tbh. Here is the image:

enter image description here

  • Welcome to TeX.SE. I'm having trouble following your question. I understand your \numbox definition, but everything after that is harder to understand. What conditional are you wanting? Could you create a MWE that shows where your conditional should do something different?
    – Teepeemm
    Oct 14, 2021 at 13:58
  • 3
    If I understand correctly, you want breakable \fboxes?
    – plante
    Oct 14, 2021 at 14:07
  • 1
    you could look at soul or ulem for breakable highlighting but don't you really just want \fbox{\parbox{.9\textwidth}{ text allowing line breaking in a box}} ? Oct 14, 2021 at 14:26
  • @plante actually yes. But I want to use it in \newcommand :) Oct 14, 2021 at 15:17
  • @davidcarlisle I am going to check it thanks :) Oct 14, 2021 at 15:18

2 Answers 2


Not an answer, but just a suggestion: tcolorbox

enter image description here

\usepackage{lipsum} % for dummy text
\newtcbox[auto counter]{\solution}[1][]{%
tcbox raise=-4mm,
grow to left by=-90pt, 
attach boxed title to top left={xshift=-90pt,yshift=-20pt}, 
tcbox width=auto limited, 
title= Solution ~\thetcbcounter #1}

Also not an answer, but to my mind one of the most useful source: https://tools.ietf.org/doc/texlive-doc/latex/tcolorbox/tcolorbox.pdf

You must log in to answer this question.

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