
並排選項給出的結果很差...
沒有sidebyside,程式碼運作良好。
\documentclass[10pt,xcolor={usenames,dvipsnames,svgnames}]{beamer}
\usepackage[most]{tcolorbox}
\definecolor{linen}{HTML}{FAF0E6}
\definecolor{sandybrown}{rgb}{0.96, 0.64, 0.38}
\begin{document}
\begin{frame}
\begin{tcolorbox}[title=Formulas,
%sidebyside,
enhanced,
colback=linen,
colframe=sandybrown,
coltext=DarkRed,
coltitle=white,
fonttitle=\small\bfseries,
fontupper=\noindent,
segmentation style={dashed, red},
segmentation code={
\path[color=red,draw]
(segmentation.west) -- (segmentation.east);}
]
Some Text \bfseries{Some text}
\begin{equation*}
a = b + c
\end{equation*}
\tcbline
\begin{equation*}
a = b + c
\end{equation*}
\tcbline
\begin{equation*}
a = b + c
\end{equation*}
%
\tcblower
Some Text \bfseries{Some text}
\begin{equation*}
a = b + c
\end{equation*}
\tcbline
\begin{equation*}
a = b + c
\end{equation*}
\tcbline
\begin{equation*}
a = b + c
\end{equation*}
\end{tcolorbox}
\end{frame}
\end{document}
答案1
在這種情況下,為什麼不只使用tabularx
內部的tcolorbox
?
\documentclass[10pt,xcolor={table, usenames, dvipsnames, svgnames}]{beamer}
\usepackage[T1]{fontenc}
\usepackage{array,tabularx}
\usepackage[most]{tcolorbox}
\definecolor{sandybrown}{rgb}{0.96,0.64,0.38}
\definecolor{linen}{HTML}{FAF0E6}
\begin{document}
\begin{frame}
\rowcolors{1}{linen}{linen!70!DarkRed}
\begin{tcolorbox}[enhanced, colback=linen, colframe=sandybrown,
title=Formulas, coltitle=white, fonttitle=\small\bfseries,
clip upper, fontupper=\sffamily,%
coltext=DarkRed,
tabularx*={\arrayrulecolor{DarkRed}}{>{\centering\arraybackslash}X|%
>{\centering\arraybackslash}X}]
Some Text \bfseries{Some text} &
Some Text \bfseries{Some text} \\\hline
$a= b+c$ & $a= b+c$\\\hline
$a= b+c$ & $a= b+c$\\\hline
$a= b+c$ & $a= b+c$
\end{tcolorbox}
\end{frame}
\end{document}
更新:
OP 影像在第一行顯示左對齊文字。在我原來的答案中,由於\multicolumn
在 tabularx tcolorbox 的第一個單元格中引入命令時出現問題,我無法重現此行為。這個問題顯示在tcolorbox、tabularx:帶有多列的第一行在 tcolorbox 環境中不起作用。現在,感謝 Thomas F. Sturm(tcolorbox
作者),這個問題有了一個臨時解決方案。
\documentclass[10pt,xcolor={table, usenames, dvipsnames, svgnames}]{beamer}
\usepackage[T1]{fontenc}
\usepackage{array,tabularx}
\usepackage[most]{tcolorbox}
\definecolor{sandybrown}{rgb}{0.96,0.64,0.38}
\definecolor{linen}{HTML}{FAF0E6}
\makeatletter
\tcbset{%
hackfortabularx/.code={%
\def\tcb@saveupperbox{%
\begin{tcb@savebox}{\tcb@upperbox}{\tcb@w@upper}
\kvtcb@fontupper\kvtcb@halignupper\kvtcb@before@upper}}
}
\makeatother
\begin{document}
\begin{frame}
\begin{tcolorbox}[enhanced, colback=linen, colframe=sandybrown,
title=Formulas, coltitle=white, fonttitle=\small\bfseries,
clip upper, hackfortabularx,
fontupper=\sffamily, coltext=DarkRed,
tabularx*={\rowcolors{1}{linen}{linen!70!DarkRed}\arrayrulecolor{DarkRed}}%
{>{\centering\arraybackslash}X|>{\centering\arraybackslash}X}]
\multicolumn{1}{l|}{Some Text \bfseries{Some text}} &
\multicolumn{1}{l}{Some Text \bfseries{Some text}} \\\hline
$a= b+c$ & $a= b+c$\\\hline
$a= b+c$ & $a= b+c$\\\hline
$a= b+c$ & $a= b+c$
\end{tcolorbox}
\end{frame}
\end{document}
第二次更新:
multicolumn
最上面規則左欄的命令問題已在 中解決tcolorbox v4.20
。不需要以前的路徑。第二個數字可以透過以下方式取得:
\documentclass[10pt,xcolor={table, usenames, dvipsnames, svgnames}]{beamer}
\usepackage[T1]{fontenc}
\usepackage{array,tabularx}
\usepackage[most]{tcolorbox}
\definecolor{sandybrown}{rgb}{0.96,0.64,0.38}
\definecolor{linen}{HTML}{FAF0E6}
\begin{document}
\begin{frame}
\begin{tcolorbox}[enhanced, colback=linen, colframe=sandybrown,
title=Formulas, coltitle=white, fonttitle=\small\bfseries,
clip upper,
fontupper=\sffamily, coltext=DarkRed,
tabularx*={\rowcolors{1}{linen}{linen!70!DarkRed}\arrayrulecolor{DarkRed}}%
{>{\centering\arraybackslash}X|>{\centering\arraybackslash}X}]
\multicolumn{1}{l|}{Some Text \bfseries{Some text}} &
\multicolumn{1}{l}{Some Text \bfseries{Some text}} \\\hline
$a= b+c$ & $a= b+c$\\\hline
$a= b+c$ & $a= b+c$\\\hline
$a= b+c$ & $a= b+c$
\end{tcolorbox}
\end{frame}
\end{document}
答案2
出現問題的原因是該sidebyside
選項似乎修改了分段節點,以便\tcblower
可以在兩個單元之間產生一條垂直線,而不是通常的水平線。因此,\tcbline
它無法按預期工作,因為它使用依賴分段節點的相同分段程式碼。
我在套件文檔中找不到\tcbline
與該sidebyside
選項一起使用的任何範例,因此不清楚是否支援這樣做。
透過將分段樣式設為實線(紅色)並刪除分段程式碼(這會導致問題),您可以獲得一個相當接近預期結果的框,並帶有實心垂直線。然而,不存在水平虛線。
變化
segmentation style={solid, red}
% segmentation code={
% \path[color=red,draw]
% (segmentation.west) -- (segmentation.east);}
產生
我能看到的唯一解決方法是使用該overlay
選項手動繪製分割線(使用按鍵停用內建分割線segmentation hidden
)。您可以使用frame
節點和 tikizlibrary庫以務實的方式執行此操作calc
:
% \usetikzlibrary{calc} % Preamble
% Box options
[title=Formulas,
sidebyside,
enhanced,
colback=linen,
colframe=sandybrown,
coltext=DarkRed,
coltitle=white,
fonttitle=\small\bfseries,
fontupper=\noindent,
segmentation hidden, % Hide the inbuilt segmentation - we're drawing our own
overlay={
\coordinate (FL) at (frame.west);
\coordinate (FT) at (frame.north);
\coordinate (FR) at (frame.east);
\coordinate (FB) at (frame.south);
\coordinate (L1) at (frame.center); % Center of frame is about right height
\coordinate (L2) at (0,1.1); % Second dashed line at height of 1.1
\def\borderthickness{2} % Offset due to borders of box
\def\titlethickness{15} % Offset due to box title
\draw [red,dashed] let \p{FT}=(FT),\p{FB}=(FB) in (\x{FB},\y{FB}+\borderthickness) -- (\x{FT},\y{FT}-\titlethickness);
\draw [red,dashed] let \p{FR}=(FR),\p{FL}=(FL),\p{L1}=(L1) in (\x{FL}+\borderthickness,\y{L1}) -- (\x{FR}-\borderthickness,\y{L1});
\draw [red,dashed] let \p{FR}=(FR),\p{FL}=(FL),\p{L2}=(L2) in (\x{FL}+\borderthickness,\y{L2}) -- (\x{FR}-\borderthickness,\y{L2});
}
]
let
有關in命令的使用\draw
,請參見,例如,這個答案。當建立未來的盒子時,您應該只需要編輯座標L1
並L2
獲得正確的水平線高度(請注意,僅使用這些座標的 y 分量)。
輸出: