如何将盒子扩展到两个分子(居中和中间空间可调),但边界在环境内enumerate
?图像是我想要制作的。我尝试执行以下操作,但显然它不够大。
\documentclass{article}
\usepackage{chemfig,chemmacros}
\chemsetup{modules=all}
\usepackage[version=4,arrows=pgf]{mhchem}
\usepackage{amsmath}
\usepackage{tabu}
\usepackage{framed}
\definecolor{SolutionColor}{gray}{0.85}
\usepackage{linegoal}
\newcommand{\mybox}[1]{\colorbox{SolutionColor}{\parbox[t]{\linegoal}{#1}}}
\begin{document}
\begin{enumerate}
\item Are the compounds shown below isomers?
\begin{center}
\mybox{
{\tabulinesep=1.6mm
\begin{tabu}{cc}
\chemfig[double bond sep=0.3em,atom sep=2.5em]{H-C(-[2]H)(-[6]H)-C(-[2]H)(-[6]H)-C(-[2]OH)(-[6]H)-C(-[2]H)(-[6]H)-H} & \chemfig[double bond sep=0.3em,atom sep=2.5em]{H-C(-[2]H)(-[6]H)-C(-[2]H)(-[6]H)-C(-[2]H)(-[6]H)-C(-[2]OH)(-[6]H)-H}
\end{tabu}}
}
\end{center}
Yes or No
Why?
\item Are the following geometric isomers?
\begin{center}
\chemfig[double bond sep=0.3em,atom sep=2.5em]{H_3C-[:-60,,2]C(-[:-120]H)=C(-[:-60]CH_3)-[:60]H}
\hspace{1em}
\chemfig{@{H}}
\hspace{1em}
\chemfig[double bond sep=0.3em,atom sep=2.5em]{H_3C-[:-60,,2]C(-[:-120]H_3C)=C(-[:-60]H)-[:60]H}
\end{center}
\begin{tikzpicture}[remember picture, overlay]
\draw[fill=gray,opacity=0.4]($(H.north east)+(6cm,1cm)$)rectangle($(H.south west)+(-5cm,-1cm)$);
\end{tikzpicture}
\end{enumerate}
\end{document}
答案1
这不是一个真正的解决方案,而是一种方法。使用 tcolorbox,您可以根据需要扩展框。
\documentclass{article}
\usepackage{chemfig}
\usepackage{tcolorbox}
\definecolor{SolutionColor}{gray}{0.85}
\begin{document}
\begin{enumerate}
\item Are the compounds shown below isomers?
\begin{tcolorbox}[colback=SolutionColor, sharp corners, boxrule=0pt, left=2mm, right=2mm, top=4mm, bottom=1cm]
\centering
\setchemfig{double bond sep=0.3em,atom sep=2.5em}
\chemfig{H-C(-[2]H)(-[6]H)-C(-[2]H)(-[6]H)-C(-[2]OH)(-[6]H)-C(-[2]H)(-[6]H)-H}
\hspace{5mm}
\chemfig{H-C(-[2]H)(-[6]H)-C(-[2]H)(-[6]H)-C(-[2]H)(-[6]H)-C(-[2]OH)(-[6]H)-H}
\end{tcolorbox}
Yes or No
Why?
\end{enumerate}
\end{document}
答案2
\documentclass{article}
\usepackage{chemfig,chemmacros}
\chemsetup{modules=all}
\usepackage[version=4,arrows=pgf]{mhchem}
\usepackage{amsmath}
\usepackage{tabu}
\usepackage{framed}
\definecolor{SolutionColor}{gray}{0.85}
\usepackage{linegoal}
\newcommand{\mybox}[1]{\colorbox{SolutionColor}{\parbox[t]{\linegoal}{#1}}}
\usepackage{tikz}
\usetikzlibrary{calc}
\begin{document}
\begin{enumerate}
\item Are the compounds shown below isomers?\\
\begin{center}
\chemfig[
double bond sep=0.3em,
atom sep=2.5em
]
{H-C(-[2]H)(-[6]H)-C(-[2]H)(-[6]H)-C(-[2]OH)(-[6]H)-C(-[2]H)(-[6]H)-@{H}H}
\qquad
\chemfig[
double bond sep=0.3em,
atom sep=2.5em
]
{H-C(-[2]H)(-[6]H)-C(-[2]H)(-[6]H)-C(-[2]H)(-[6]H)-C(-[2]OH)(-[6]H)-H}
\end{center}
Yes or No
\\
Why?
\end{enumerate}
\begin{tikzpicture}[remember picture, overlay]
\draw[red,fill=gray,opacity=0.5]($(H.north east)+(6cm,1cm)$)rectangle($(H.south
west)+(-5cm,-1cm)$);
\end{tikzpicture}
\end{document}
编辑以解决上面评论部分中的 OP 查询
@jsbibra 抱歉,如果分子不是线性的,我该如何修改 tikz 锚点 @{H}?我已将其附加到上面的 MWE。– Dave2627
再次选择@H作为标签会混淆tikz,因为它已经在第一个例子中使用过,只需使用另一个字母表如@XYZ作为标签并继续
\documentclass{article}
\usepackage{chemfig,chemmacros}
\chemsetup{modules=all}
\usepackage[version=4,arrows=pgf]{mhchem}
\usepackage{amsmath}
\usepackage{tabu}
\usepackage{framed}
\definecolor{SolutionColor}{gray}{0.85}
\usepackage{linegoal}
\newcommand{\mybox}[1]{\colorbox{SolutionColor}{\parbox[t]{\linegoal}{#1}}}
\usepackage{tikz}
\usetikzlibrary{calc}
\begin{document}
\begin{enumerate}
\item Are the compounds shown below isomers?\\
\begin{center}
\chemfig[
double bond sep=0.3em,
atom sep=2.5em
]
{H-C(-[2]H)(-[6]H)-C(-[2]H)(-[6]H)-C(-[2]OH)(-[6]H)-C(-[2]H)(-[6]H)-@{H}H}
\qquad
\chemfig[
double bond sep=0.3em,
atom sep=2.5em
]
{H-C(-[2]H)(-[6]H)-C(-[2]H)(-[6]H)-C(-[2]H)(-[6]H)-C(-[2]OH)(-[6]H)-H}
\end{center}
Yes or No
\\
Why?
\\
\item Are the following geometric isomers?
\begin{center}
\chemfig[double bond sep=0.3em,atom sep=2.5em]{H_3C-[:-60,,2]C(-[:-120]H)=C(-[:-60]CH_3)-[:60]@{X}H}
\hspace{1em}
% \chemfig{@{H}}
\hspace{1em}
\chemfig[double bond sep=0.3em,atom sep=2.5em]{H_3C-[:-60,,2]C(-[:-120]H_3C)=C(-[:-60]H)-[:60]H}
\end{center}
\end{enumerate}
\begin{tikzpicture}[remember picture, overlay]
\draw[red,fill=gray,opacity=0.5]($(H.north east)+(6cm,1cm)$)rectangle($(H.south
west)+(-5cm,-1cm)$);
\draw[blue,line width=2pt,fill=teal,opacity=0.3]($(X.north east)+(5cm,4pt)$)rectangle($(X.south
west)+(-3cm,-5em)$);
\end{tikzpicture}
\end{document}