3

How shall I change the mybox style defined below such that it fits in the second column?

\documentclass[twocolumn,11pt]{article}
\usepackage{tikz}
\usepackage{lipsum}

\tikzstyle{mybox} = [draw=black, very thick, rectangle, rounded corners, inner ysep=5pt, inner xsep=5pt]

\begin{document}

\lipsum[2-4]

\vspace{10pt}\begin{tikzpicture}
\node [mybox] (box){
\begin{minipage}{.96\textwidth}
\textbf{lipsum[2-4] -} In this example, lipsum package is used to print dummy text below chapter title. lipsum[2-4] prints lorem ipsum text from paragraph 2 to paragraph 4.
\end{minipage}
};
\end{tikzpicture}


\end{document}

enter image description here

  • 1
    Reduce the width of minipage. Say, change 0.96\textwidth to 0.5\textwidth or to \linewidth. – nidhin Sep 29 at 12:58
  • @nidhin Great, thanks! Do you mind posting as an answer so I can accept it? – mforets Sep 29 at 13:01
3

mybox is flowing out because the width you provided for minipage, 0.96\textwidth, is larger than the linewidth (=0.5*\textwidth). Reduce the width to 0.5*\textwidth or below. Alternatively, use \linewidth instead of \textwidth.

enter image description here

\documentclass[twocolumn,11pt]{article}
\usepackage{tikz}
\usepackage{lipsum}

\tikzstyle{mybox} = [draw=black, very thick, rectangle, rounded corners, inner ysep=5pt, inner xsep=5pt]

\begin{document}

\lipsum[2-4]

\vspace{10pt}\begin{tikzpicture}
\node [mybox] (box){
\begin{minipage}{.96\linewidth}
\textbf{lipsum[2-4] -} In this example, lipsum package is used to print dummy text below chapter title. lipsum[2-4] prints lorem ipsum text from paragraph 2 to paragraph 4.
\end{minipage}
};
\end{tikzpicture}


\end{document}
| improve this answer | |
3

I suggest to use a tcolorbox instead of TikZ nodes:

\documentclass[twocolumn,11pt]{article}
\usepackage[most]{tcolorbox}
\usepackage{lipsum}

\newtcolorbox{mybox}{colback=white, size=fbox, colframe=black, boxrule=1.2pt}

\begin{document}

\lipsum[2-4]

\begin{mybox}
\textbf{lipsum[2-4] -} In this example, lipsum package is used to print dummy text below chapter title. lipsum[2-4] prints lorem ipsum text from paragraph 2 to paragraph 4.
\end{mybox}

\end{document}

enter image description here

| 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.