# Single column tikz text box

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}


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

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.

\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}


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}