问题:
现在我正在迷你页面中工作,问题是迷你页面的组件放置位置不正确。我想减少它们之间的空间,并且两者都从顶部的同一行开始(我的意思是在同一行水平上)
梅威瑟:
\documentclass[12pt,a4paper]{article}
\usepackage[a4paper,vmargin=0.5in,hmargin=0.5in]{geometry}
\usepackage[utf8]{inputenc}
\usepackage[misc]{ifsym}
\usepackage{amsmath,amsfonts,amssymb,cancel}
\usepackage{array,booktabs}
\usepackage{forest}
\usepackage{parskip}
\usepackage{tcolorbox}
\begin{document}
\begin{minipage}[t]{.45\textwidth}
\begin{forest}
for tree={circle,draw, l sep=10pt}
[140,black
[2]
[70
[2]
[35
[5]
[7]
]
]
]
\end{forest}
\end{minipage}
%\hfill
\begin{minipage}[b]{.55\textwidth}
\begin{align*}
140 &= 2 \times 2 \times 5 \times 7&\\
&= 2^2 \times 5 \times 7
\end{align*}
\end{minipage}
\end{document}
答案1
的参考点forest
位于底部。您可以将其置于顶部,以便它与带有\adjustbox
和 的标准文本行对齐valign=t
。对于等式,请使用aligned
。
最后,决定对象之间的间距,这里\quad
使用。
\documentclass[12pt,a4paper]{article}
\usepackage{amsmath}
\usepackage{forest}
\usepackage{adjustbox}
\begin{document}
\adjustbox{valign=t}{%
\begin{forest}
for tree={circle,draw, l sep=10pt}
[140,black
[2]
[70
[2]
[35
[5]
[7]
]
]
]
\end{forest}%
}% end of adjustbox (the % next to the brace is important
\qquad
$\begin{aligned}[t]
140 &= 2 \times 2 \times 5 \times 7&\\
&= 2^2 \times 5 \times 7
\end{aligned}$
\end{document}
通过该baseline
选项,您可以垂直对齐两个部分,以便 140 的两个实例位于同一高度。
\documentclass[12pt,a4paper]{article}
\usepackage{amsmath}
\usepackage{forest}
\begin{document}
\begin{forest} baseline, for tree={circle,draw, l sep=10pt}
[140,black
[2]
[70
[2]
[35
[5]
[7]
]
]
]
\end{forest}\qquad
$\begin{aligned}[t]
140 &= 2 \times 2 \times 5 \times 7&\\
&= 2^2 \times 5 \times 7
\end{aligned}$
\end{document}
对于垂直居中,
\documentclass[12pt,a4paper]{article}
\usepackage{amsmath}
\usepackage{forest}
\usepackage{adjustbox}
\begin{document}
\begin{adjustbox}{valign=c}
\begin{forest} baseline=center, for tree={circle,draw, l sep=10pt}
[140,black
[2]
[70
[2]
[35
[5]
[7]
]
]
]
\end{forest}
\end{adjustbox}\qquad
$\begin{aligned}
140 &= 2 \times 2 \times 5 \times 7&\\
&= 2^2 \times 5 \times 7
\end{aligned}$
\end{document}
如果您想在数学显示中设置它,请省略$
字符并利用gathered
。
\documentclass[12pt,a4paper]{article}
\usepackage{amsmath}
\usepackage{forest}
\begin{document}
\begin{equation*}
\begin{gathered}
\begin{forest} baseline=center, for tree={circle,draw, l sep=10pt}
[140,black
[2]
[70
[2]
[35
[5]
[7]
]
]
]
\end{forest}
\end{gathered}\qquad
\begin{aligned}
140 &= 2 \times 2 \times 5 \times 7&\\
&= 2^2 \times 5 \times 7
\end{aligned}
\end{equation*}
\end{document}
答案2
\documentclass[12pt,a4paper]{article}
\usepackage[a4paper,vmargin=0.5in,hmargin=0.5in]{geometry}
\usepackage[utf8]{inputenc}
\usepackage[misc]{ifsym}
\usepackage{amsmath,amsfonts,amssymb,cancel}
\usepackage{array,booktabs}
\usepackage{forest}
\usepackage{parskip}
\usepackage{tcolorbox}
\usepackage{varwidth}
\begin{document}
\begin{varwidth}[t]{.45\textwidth} \vspace{0pt}
\begin{forest} for tree={circle,draw, l sep=10pt} [140,black [2] [70
[2] [35 [5] [7] ]
] ]
\end{forest}
\end{varwidth}
%\hfill
\begin{varwidth}[t]{.55\textwidth} \vspace{0pt}
$ 140 = 2 \times 2 \times 5 \times 7 = 2^2 \times 5 \times 7 $
\end{varwidth}
\end{document}