我在mdframed
使用与以下产品组合时遇到了一些问题:tabular
。在弄清楚如何让框架的宽度与对象(在我的情况下是表格)的宽度相匹配之后,我使用了一个描述这里,桌子到两边框架之间的空间并不相同。
左侧似乎还有更多空间,大约 30%。以下是 MWE:
\documentclass[a4paper,12pt]{article}
\usepackage{environ}
\usepackage{varwidth}
\usepackage{siunitx}
\usepackage[version=3]{mhchem} % den nemmeste måde at skrive kemiske navne
\usepackage[framemethod=TikZ]{mdframed} % frame i images/figures
\newlength{\MyMdframedWidthTweak}%
\NewEnviron{MyMdframed}[1][]{%
\setlength{\MyMdframedWidthTweak}{\dimexpr%
+\mdflength{innerleftmargin}
+\mdflength{innerrightmargin}
+\mdflength{leftmargin}
+\mdflength{rightmargin}
}%
\savebox0{%
\begin{varwidth}{\dimexpr\linewidth-\MyMdframedWidthTweak\relax}%
\BODY
\end{varwidth}%
}%
\begin{mdframed}[
linecolor=red,
linewidth=3pt,
roundcorner=5pt,
userdefinedwidth=\dimexpr\wd0+\MyMdframedWidthTweak\relax,
#1]
\usebox0
\end{mdframed}
}
\begin{document}
\begin{MyMdframed}
\begin{tabular}{l r}
Trivialnavn & vanillin \\
Sumformel & \ce{C8H8O3} \\
Kemisk struktur & \ce{(CH3O)C6H3(OH)CHO} \\
IUPAC & 4-hydroxy-3-methoxybenzaldehyde \\
CAS nummer & 121-33-5 \\
Farve & hvid-gullig \\
Duft & behagelig, blomstret \\
Molarmasse & \SI{152,15}{\gram\per\mole} \\
Smeltepunkt & \SI{82}{\celsius} \\
Kogepunkt & \SI{170}{\celsius} \\
Kilde & Wolfram|Alpha \& Databogen
\end{tabular}
\end{MyMdframed}
\end{document}
不是最小,但你明白我的意思。我认为这与表格宽度的计算方式有关,但我不知道如何调整它。当我使用 plaintikz
完成所述任务时,我遇到了同样的问题这里。
答案1
您必须添加两倍的linewidth
框架(这里是 3pt)到userdefinedwidth
userdefinedwidth=\dimexpr\wd0+\MyMdframedWidthTweak+6pt\relax,
完整代码:
\documentclass[a4paper,12pt]{article}
\usepackage{environ}
\usepackage{varwidth}
\usepackage{siunitx}
\usepackage[version=3]{mhchem} % den nemmeste måde at skrive kemiske navne
\usepackage[framemethod=TikZ]{mdframed} % frame i images/figures
\newlength{\MyMdframedWidthTweak}%
\NewEnviron{MyMdframed}[1][]{%
\setlength{\MyMdframedWidthTweak}{\dimexpr%
+\mdflength{innerleftmargin}
+\mdflength{innerrightmargin}
+\mdflength{leftmargin}
+\mdflength{rightmargin}
}%
\savebox0{%
\begin{varwidth}{\dimexpr\linewidth-\MyMdframedWidthTweak\relax}%
\BODY
\end{varwidth}%
}%
\begin{mdframed}[
linecolor=red,
linewidth=3pt,
roundcorner=5pt,
userdefinedwidth=\dimexpr\wd0+\MyMdframedWidthTweak+6pt\relax,
#1]
\usebox0%
\end{mdframed}%
}
\begin{document}
\begin{MyMdframed}
\begin{tabular}{l r}
Trivialnavn & vanillin \\
Sumformel & \ce{C8H8O3} \\
Kemisk struktur & \ce{(CH3O)C6H3(OH)CHO} \\
IUPAC & 4-hydroxy-3-methoxybenzaldehyde \\
CAS nummer & 121-33-5 \\
Farve & hvid-gullig \\
Duft & behagelig, blomstret \\
Molarmasse & \SI{152,15}{\gram\per\mole} \\
Smeltepunkt & \SI{82}{\celsius} \\
Kogepunkt & \SI{170}{\celsius} \\
Kilde & Wolfram|Alpha \& Databogen
\end{tabular}%
\end{MyMdframed}
\end{document}