单列 tikz 文本框

单列 tikz 文本框

我应如何更改mybox下面定义的样式以使其适合第二列?

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

在此处输入图片描述

答案1

mybox溢出,因为您为 提供的宽度minipage大于0.96\textwidth( linewidth=0.5* \textwidth)。请将宽度减小到0.5*\textwidth或以下。或者,使用\linewidth代替\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}

答案2

我建议使用tcolorbox而不是TikZ节点:

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

在此处输入图片描述

相关内容