我想将tcolorbox
环境分成两列,如下所示:
+---------------------------------------------------------------------------+
| Definition. Lorem ipsum dolor sit amet, consectetur adipiscing elit. |
| Praesent ac sem commodo, venenatis nisl ac, pharetra arcu. | <-- tcolorbox
| Cras accumsan pharetra facilisis. Vivamus mattis vulputate |
| dui, quis vulputate metus pretium a. |
+---------------------------------------------------------------------------+
我首先尝试将一个两列表格放入 tcolorbox,但这甚至无法编译(LaTeX 错误:浮点数丢失)。然后,我尝试将两个小页面(一个用于 Definition.,另一个用于文本)放入 tcolorbox 中以将其一分为二,但对齐方式被破坏,以至于我甚至不知道如何描述这个问题:
\documentclass{standalone}
\usepackage{tcolorbox, xcolor, lmodern}
\definecolor{jblueleft}{RGB}{0, 79, 144}
\definecolor{jblueinner}{RGB}{240, 248, 255}
\newtcolorbox{exampleBox}{textmarker,
borderline west={3pt}{0pt}{jblueleft},
colback=jblueinner} % Define the box style.
\newcommand{\definition}[1]{
\begin{exampleBox}
\fboxsep=0pt
\noindent\begin{minipage}[t]{0.5\linewidth}
{\fontfamily{lmss}\selectfont\textcolor{jblueleft}{\textbf{Definition}.}}
\end{minipage}
\hfill
\begin{minipage}[t]{0.5\linewidth}
#1
\end{minipage}
\end{exampleBox}
}
\begin{document}
\definition{For a particle traversing a 2-dimensional path \(c\) in a force field \(\bmv F(x,y)=f(x,y)\ui+g(x,y)\uj\), the work integral is
\begin{align*}
W&=\int_c \bmv F\cdot\,\mathrm d\bmv r\\
&=\int_c f(x,y)\,\mathrm dx+\int_c g(x,y)\,\mathrm dy
\end{align*}}
\end{document}
以下给出了错误输出:
答案1
tcolorbox
使用选项的另一种方法sidebyside
:
\documentclass[margin=5pt]{standalone}
\usepackage{amsmath}
\usepackage{bm}
\usepackage{tcolorbox, xcolor, lmodern}
\tcbuselibrary{skins}
\definecolor{jblueleft}{RGB}{0, 79, 144}
\definecolor{jblueinner}{RGB}{240, 248, 255}
% my guess to missing definitions
\newcommand\bmv{\bm{v}}
\newcommand\ui{\mathbf{i}}
\newcommand\uj{\mathbf{j}}
\tcbset{
textmarker/.style={
enhanced,
sharp corners,
boxrule=0pt,
}
}
% end of my guess
\newsavebox{\exampleTitle}
\savebox\exampleTitle{%
\fontfamily{lmss}\bfseries
\textcolor{jblueleft}{Definition.}}
\newtcolorbox{exampleBox}{
textmarker,
borderline west={3pt}{0pt}{jblueleft},
colback=jblueinner,
before upper=\usebox\exampleTitle,
sidebyside,
lower separated=false,
sidebyside align=top,
sidebyside gap=5pt,
lefthand width=\the\wd\exampleTitle,
} % Define the box style.
\newcommand{\definition}[1]{%
\begin{exampleBox}
\tcblower
#1%
\end{exampleBox}%
}
\begin{document}
\definition{For a particle traversing a 2-dimensional path \(c\) in a force field \(\bmv F(x,y)=f(x,y)\ui+g(x,y)\uj\), the work integral is
\begin{align*}
W&=\int_c \bmv F\cdot\,\mathrm d\bmv r\\
&=\int_c f(x,y)\,\mathrm dx+\int_c g(x,y)\,\mathrm dy
\end{align*}}
\end{document}
OP 的示例不完整:没有提供命令、和样式键的定义。我改用\bmv
了\ui
我的\uj
猜测。tcolorbox
textmaker
嗯\@hangfrom
,来自 LaTeX2e 内核的 会让示例更短。输出与上面相同。
\documentclass[margin=5pt]{standalone}
\usepackage{amsmath}
\usepackage{bm}
\usepackage{tcolorbox, xcolor, lmodern}
\tcbuselibrary{skins}
\definecolor{jblueleft}{RGB}{0, 79, 144}
\definecolor{jblueinner}{RGB}{240, 248, 255}
% my guess to missing definitions
\newcommand\bmv{\bm{v}}
\newcommand\ui{\mathbf{i}}
\newcommand\uj{\mathbf{j}}
\tcbset{
textmarker/.style={
enhanced,
sharp corners,
boxrule=0pt,
}
}
% end of my guess
\makeatletter
\newtcolorbox{exampleBox}{
textmarker,
borderline west={3pt}{0pt}{jblueleft},
colback=jblueinner,
before upper=\@hangfrom{%
\fontfamily{lmss}\bfseries
\textcolor{jblueleft}{Definiton. }% note the space after "."
},
} % Define the box style.
\makeatother
\newcommand{\definition}[1]{%
\begin{exampleBox}
#1%
\end{exampleBox}%
}
\begin{document}
\definition{For a particle traversing a 2-dimensional path \(c\) in a force field \(\bmv F(x,y)=f(x,y)\ui+g(x,y)\uj\), the work integral is
\begin{align*}
W&=\int_c \bmv F\cdot\,\mathrm d\bmv r\\
&=\int_c f(x,y)\,\mathrm dx+\int_c g(x,y)\,\mathrm dy
\end{align*}}
\end{document}
答案2
我几乎已经完成了——结果发现剩下要做的就是将0.5
minipages 调整到我想要的正确比例。事实上,我成功地将 tcolorbox 分成了两个部分,它们只是相等的部分,而我并不想这样。
我把0.5
和0.5
改为0.15
和0.85
。