我使用 将一些文本放入框中\tcbox
。然后我打算在框中创建一个新行,如下所示:
\tcbox{%
\begin{small}
\begin{concmath}
first line\\ % here a new line is expected in the box.
second line. \\ \\
\end{concmath}
\end{small}\\
}%
但是,框中并未创建新行。
附言 concmath
用于根据需要更改字体。字体更改定义如下:
\usepackage[T1]{fontenc}
\DeclareMathVersion{concmath}
\SetMathAlphabet{\mathrm}{concmath}{\encodingdefault}{ccr}{m}{n}
\newenvironment{concmath}
{\fontfamily{ccr}\selectfont\mathversion{concmath}}
{\ignorespacesafterend}
答案1
使用选项tikznode
。它记录在tcolorbox
文档,第 4.12 节。例如,
\documentclass{article}
\usepackage{tcolorbox}
\usepackage{tikz}
\begin{document}
\tcbox[tikznode]{%
\small
text \\ text
}
\end{document}
更新
和
\tcbox[tikznode]{%
\begin{small}
\begin{concmath}
first line\\ % here a new line is expected in the box.
second line. \\ \\
\end{concmath}
\end{small}\\
}%
错误
! Extra }, or forgotten \endgroup.
\tikz@@align@newline [#1]->\egroup
\tikz@align@continue \pgfmathparse {#1}\l...
引发。tikz
只有在简单环境中输入多行节点文本时,才能重现此问题,例如
\documentclass{article}
\usepackage{tikz}
\begin{document}
\tikz \node[align=center] {
\begin{small}
first line\\ % here a new line is expected in the box.
second line. \\ \\
\end{small}
};
\end{document}
\\
我认为这是由简单环境引入的内部节点文本和额外组的重新定义引起的。
由于small
和concmath
环境都进行字体设置,因此你可以将它们的效果移到某些字体选项中。例如,
\documentclass{article}
\usepackage[T1]{fontenc}
\DeclareMathVersion{concmath}
\SetMathAlphabet{\mathrm}{concmath}{\encodingdefault}{ccr}{m}{n}
\newenvironment{concmath}
{\fontfamily{ccr}\selectfont\mathversion{concmath}}
{\ignorespaces}
\usepackage{tcolorbox}
\usepackage{tikz}
\newtcbox{\xtcbox}{
tikznode,
fontupper=\small\fontfamily{ccr}\selectfont\mathversion{concmath}
}
\begin{document}
\xtcbox{%
first line\\ % here a new line is expected in the box.
second line. \\ \\
}
\end{document}
small
此外,为了保持环境和的使用concmath
,您可以将盒子内容嵌套在varwidth
由包定义的环境中varwidth
。
\documentclass{article}
\usepackage[T1]{fontenc}
\DeclareMathVersion{concmath}
\SetMathAlphabet{\mathrm}{concmath}{\encodingdefault}{ccr}{m}{n}
\newenvironment{concmath}
{\fontfamily{ccr}\selectfont\mathversion{concmath}}
{\ignorespaces}
\usepackage{tcolorbox}
\usepackage{varwidth}
\begin{document}
\tcbox{%
\begin{varwidth}{\linewidth}
\begin{small}
\begin{concmath}
first line\\ % here a new line is expected in the box.
second line. \\ \\
\end{concmath}
\end{small}\\
\end{varwidth}
}
\end{document}
答案2
简单的答案是使用tcolorbox
而不是\tcbox
,如下所示:
\begin{tcolorbox}
\begin{small}
\begin{concmath}
first line\\ % here a new line is expected in the box.
second line.
\end{concmath}
\end{small}
\end{tcolorbox}