我经常遇到这种情况,并且通常会尝试不同的方法,直到勉强可以接受,但我真的不明白发生了什么。
这:
\documentclass{scrreprt}
\usepackage[margin=1in]{geometry}
\usepackage{tikz,tkz-euclide}
\usetkzobj{all}
\begin{document}
\fbox{
\begin{tikzpicture}[scale=1.35]
\coordinate (P) at (0,0);
\coordinate (R) at (0,-1.7);
\coordinate (S) at (1.7,-1.7);
\coordinate (T) at (3,0);
\coordinate (U) at (0.4,1.7);
\coordinate (V) at (-1.7,1.7);
\coordinate (Q) at (-1.7,0);
\draw[<->] (Q)node[ left ]{Q} -- (T)node[ right ]{T} ;
\draw[<->] (R)node[below]{R} -- (P)node[below left=1em and 1em]{P} -- (U)node[right]{U};
\draw[<->] (V)node[left]{B} -- (S)node[right]{S} ;
\draw (-0.4em,-0.4em) rectangle (0,0);
\tkzMarkAngle[size=0.4,mark=|](V,P,Q);
\tkzMarkAngle[size=0.4,mark=|](R,P,S);
\tkzMarkAngle[size=0.4,mark=|](S,P,T);
\tkzMarkSegment[size=0.4,pos=0.5,mark=|](V,S);
\end{tikzpicture}
}%
\hfill
\fbox{
\begin{minipage}[t]{ 0.46\textwidth}\
I would like to have this box start at the top of the one to the left
\end{minipage}%
}
\end{document}
最后看起来像这样
答案1
方法 1:使用一张 TikZ 图片表示所有内容
我确实使用了附加包,tikzpagenodes
以便于定位和使用 TikZ 库fit
来创建围绕图形的节点,但所有内容都可以进入一个tikzpicture
环境中。
为了有效地使用页面节点,您需要调用remember picture
以便 TikZ 记住这些节点的位置以及相对于它们定义的节点。
尽管图像没有显示出来,但我留下了showframe
一些键,geometry
以便您可以看到事物如何与页边距对齐。
\documentclass{scrreprt}
\usepackage[margin=1in]{geometry}
\usepackage{tikz,tkz-euclide}
\usetikzlibrary{fit}
\usetkzobj{all}
\usepackage{tikzpagenodes}
\begin{document}
\noindent
\begin{tikzpicture}[scale=1.35,baseline=(current bounding box.north),remember picture]
\coordinate (P) at (0,0);
\coordinate (R) at (0,-1.7);
\coordinate (S) at (1.7,-1.7);
\coordinate (T) at (3,0);
\coordinate (U) at (0.4,1.7);
\coordinate (V) at (-1.7,1.7);
\coordinate (Q) at (-1.7,0);
\draw[<->] (Q)node[ left ]{Q} -- (T)node[ right ]{T} ;
\draw[<->] (R)node[below]{R} -- (P)node[below left=1em and 1em]{P} -- (U)node[right]{U};
\draw[<->] (V)node[left]{B} -- (S)node[right]{S} ;
\draw (-0.4em,-0.4em) rectangle (0,0);
\tkzMarkAngle[size=0.4,mark=|](V,P,Q);
\tkzMarkAngle[size=0.4,mark=|](R,P,S);
\tkzMarkAngle[size=0.4,mark=|](S,P,T);
\tkzMarkSegment[size=0.4,pos=0.5,mark=|](V,S);
\node[draw,
fit=(current bounding box.north west)
(current bounding box.south east),
] (LEFT) {};
\node[anchor=north east,
text width=0.46\textwidth,
draw,
]
(B) at (LEFT.north east-|current page text area.east)
{I would like to have this box start at the top of the one to the left};
\end{tikzpicture}%%
\end{document}
方法 #2:使用 TikZ 图片和小页面
让 TikZ 图片与小页面正确对齐对我来说比我想象的要麻烦得多。因此,我并没有尝试让两个环境就图片的位置达成一致,而是顶部由于每个都是相对的(我可以得到非常接近但不完全一样的结果),我决定使用\raisebox
。瞧!它运行完美。而且不需要额外的软件包。
\documentclass{scrreprt}
\usepackage[margin=1in]{geometry}
\usepackage{tikz,tkz-euclide}
\usetkzobj{all}
\begin{document}
\noindent
\raisebox{-\dimexpr\height}
[0pt]
[\dimexpr\height+\depth]
{\begin{tikzpicture}
\coordinate (P) at (0,0);
\coordinate (R) at (0,-1.7);
\coordinate (S) at (1.7,-1.7);
\coordinate (T) at (3,0);
\coordinate (U) at (0.4,1.7);
\coordinate (V) at (-1.7,1.7);
\coordinate (Q) at (-1.7,0);
\draw[<->] (Q)node[ left ]{Q} -- (T)node[ right ]{T} ;
\draw[<->] (R)node[below]{R} -- (P)node[below left=1em and 1em]{P} -- (U)node[right]{U};
\draw[<->] (V)node[left]{B} -- (S)node[right]{S} ;
\draw (-0.4em,-0.4em) rectangle (0,0);
\tkzMarkAngle[size=0.4,mark=|](V,P,Q);
\tkzMarkAngle[size=0.4,mark=|](R,P,S);
\tkzMarkAngle[size=0.4,mark=|](S,P,T);
\tkzMarkSegment[size=0.4,pos=0.5,mark=|](V,S);
\draw (current bounding box.north east) rectangle (current bounding box.south west);
\end{tikzpicture}}%%
\hfill
\raisebox{-\height}
[0pt]
[\dimexpr\height+\depth]
{\fbox{%%
\begin{minipage}{ 0.46\textwidth}
I would like to have this box start at the top of the one to the left
\end{minipage}}}
\end{document}
答案2
您可以使用\adjustbox
两个框并将其对齐到它们的顶部。
\documentclass{scrreprt}
\usepackage[margin=1in]{geometry}
\usepackage{adjustbox}
\usepackage{tikz,tkz-euclide}
\usetkzobj{all}
\begin{document}
\adjustbox{valign=T}{\fbox{%
\begin{tikzpicture}[scale=1.35]
\coordinate (P) at (0,0);
\coordinate (R) at (0,-1.7);
\coordinate (S) at (1.7,-1.7);
\coordinate (T) at (3,0);
\coordinate (U) at (0.4,1.7);
\coordinate (V) at (-1.7,1.7);
\coordinate (Q) at (-1.7,0);
\draw[<->] (Q)node[ left ]{Q} -- (T)node[ right ]{T} ;
\draw[<->] (R)node[below]{R} -- (P)node[below left=1em and 1em]{P} -- (U)node[right]{U};
\draw[<->] (V)node[left]{B} -- (S)node[right]{S} ;
\draw (-0.4em,-0.4em) rectangle (0,0);
\tkzMarkAngle[size=0.4,mark=|](V,P,Q);
\tkzMarkAngle[size=0.4,mark=|](R,P,S);
\tkzMarkAngle[size=0.4,mark=|](S,P,T);
\tkzMarkSegment[size=0.4,pos=0.5,mark=|](V,S);
\end{tikzpicture}%
}}%
\hfill
\adjustbox{valign=T}{\fbox{%
\begin{minipage}{0.46\textwidth}
I would like to have this box start at the top of the one to the left
\end{minipage}%
}}
\end{document}
当心缺失%
,否则您会得到不需要的空间。