我想让“图例”出现在绘图的右侧...有什么建议吗?我尝试调整锚定方向和斜率,但没有成功。
\documentclass[tikz,border=10pt]{standalone}
\usepackage{amssymb}
\usetikzlibrary{positioning}
\begin{document}
\begin{center}
\begin{tikzpicture}
\foreach \x/\y/\z in {1/1/9,3.2/1/10,2/1.5/8,1.5/2/6, 2.5/2/7,1.2/2.5/2,2/2.5/4,3.1/2.5/5,2/3/1,2.9/2.9/3}{
\node[circle,fill,inner sep=1.5pt,outer sep=0pt,label={[xshift=-3pt,yshift=2pt,scale=0.7]-60:$\mathrm{P}_{\z}$}] (\z) at (\x,\y){};
}
\node[draw,rectangle,anchor=south west,minimum width=4cm,minimum height=4cm] (A) at (0,0) {};
\node[draw,rectangle,top color=white,bottom color=gray!60,anchor=south west,minimum width=4cm,minimum height=4cm] (B) at (1.3,5) {};
\draw (A.north west) -- (B.north west)
(A.north east) -- (B.north east)
(A.south west) -- (B.south west)
(A.south east) -- (B.south east);
\node (U) at (-1,5) {$\mathrm{U}_1$};
\node at (-1,2) {$\mathrm{U}_2$};
\draw (U.east) edge[bend left] (1.west);
\draw (U.east) edge[bend right] (2.south);
\node[anchor=west] at (0,-1) {Legend:};
\node[anchor=west] at (0,-1.5) {{\tiny$\blacksquare$} $\mathrm{U}_1$ - instantiated universal};
\node[anchor=west] at (0,-2) {{\tiny$\blacksquare$} $\mathrm{U}_2$ - uninstantiated universal};
\node[anchor=west] at (0,-2.5) {{\tiny$\blacksquare$} $\mathrm{P}_1 \ldots \mathrm{P}_2$ - thin particulars};
\node[anchor=west] at (0,-3) {{\tiny$\blacksquare$} $\mathrm{P}_3 \ldots \mathrm{P}_{10}$ - bare particulars};
\node[anchor=center,above = 0.1cm of B.north west,font=\bfseries\large] {Space-time manifold};
\end{tikzpicture}
\end{center}
\end{document}
答案1
这是否接近您的需求?使用scope
环境将您的图例包裹在里面并应用[shift={(xx,yy)}]
以满足您对位置的需求。此外,对于标题流形,您可以使用xshift=xx
将其移动到右侧。
代码
\documentclass[tikz,border=10pt]{standalone}
\usepackage{amssymb}
\usetikzlibrary{positioning}
\begin{document}
\begin{center}
\begin{tikzpicture}
\foreach \x/\y/\z in {1/1/9,3.2/1/10,2/1.5/8,1.5/2/6, 2.5/2/7,1.2/2.5/2,2/2.5/4,3.1/2.5/5,2/3/1,2.9/2.9/3}{
\node[circle,fill,inner sep=1.5pt,outer sep=0pt,label={[xshift=-3pt,yshift=2pt,scale=0.7]-60:$\mathrm{P}_{\z}$}] (\z) at (\x,\y){};
}
\node[draw,rectangle,anchor=south west,minimum width=4cm,minimum height=4cm] (A) at (0,0) {};
\node[draw,rectangle,top color=white,bottom color=gray!60,anchor=south west,minimum width=4cm,minimum height=4cm] (B) at (1.3,5) {};
\draw (A.north west) -- (B.north west)
(A.north east) -- (B.north east)
(A.south west) -- (B.south west)
(A.south east) -- (B.south east);
\node (U) at (-1,5) {$\mathrm{U}_1$};
\node at (-1,2) {$\mathrm{U}_2$};
\begin{scope}[shift={(6cm,5cm)}]
\draw (U.east) edge[bend left] (1.west);
\draw (U.east) edge[bend right] (2.south);
\node[anchor=west] at (0,-1) {Legend:};
\node[anchor=west] at (0,-1.5) {{\tiny$\blacksquare$} $\mathrm{U}_1$ - instantiated universal};
\node[anchor=west] at (0,-2) {{\tiny$\blacksquare$} $\mathrm{U}_2$ - uninstantiated universal};
\node[anchor=west] at (0,-2.5) {{\tiny$\blacksquare$} $\mathrm{P}_1 \ldots \mathrm{P}_2$ - thin particulars};
\node[anchor=west] at (0,-3) {{\tiny$\blacksquare$} $\mathrm{P}_3 \ldots \mathrm{P}_{10}$ - bare particulars};
\end{scope}
\node[anchor=center,above = 0.1cm of B.north west,font=\bfseries\large, xshift=1cm] {Space-time manifold};
\end{tikzpicture}
\end{center}
\end{document}
答案2
您可以使用定位库(您已经加载)。
\documentclass[tikz,border=10pt]{standalone}
\usepackage{amssymb}
\usetikzlibrary{positioning}
\begin{document}
\begin{tikzpicture}
\foreach \x/\y/\z in {1/1/9,3.2/1/10,2/1.5/8,1.5/2/6, 2.5/2/7,1.2/2.5/2,2/2.5/4,3.1/2.5/5,2/3/1,2.9/2.9/3}{
\node[circle,fill,inner sep=1.5pt,outer sep=0pt,label={[xshift=-3pt,yshift=2pt,scale=0.7]-60:$\mathrm{P}_{\z}$}] (\z) at (\x,\y){};
}
\node[draw,rectangle,anchor=south west,minimum width=4cm,minimum height=4cm] (A) at (0,0) {};
\node[draw,rectangle,top color=white,bottom color=gray!60,anchor=south west,minimum width=4cm,minimum height=4cm] (B) at (1.3,5) {};
\draw (A.north west) -- (B.north west)
(A.north east) -- (B.north east)
(A.south west) -- (B.south west)
(A.south east) -- (B.south east);
\node (U) at (-1,5) {$\mathrm{U}_1$};
\node at (-1,2) {$\mathrm{U}_2$};
\draw (U.east) edge[bend left] (1.west);
\draw (U.east) edge[bend right] (2.south);
\node[anchor=west,below right = 0cm and 1cm of B] {Legend:};
\node[anchor=west,below right = 0.5cm and 1.25cm of B] {{\tiny$\blacksquare$} $\mathrm{U}_1$ - instantiated universal};
\node[anchor=west,below right = 1cm and 1.25cm of B] {{\tiny$\blacksquare$} $\mathrm{U}_2$ - uninstantiated universal};
\node[anchor=west,below right = 1.5cm and 1.25cm of B] {{\tiny$\blacksquare$} $\mathrm{P}_1 \ldots \mathrm{P}_2$ - thin particulars};
\node[anchor=west,below right = 2cm and 1.25cm of B] {{\tiny$\blacksquare$} $\mathrm{P}_3 \ldots \mathrm{P}_{10}$ - bare particulars};
\node[anchor=center,above = 0.1cm of B.north west,font=\bfseries\large] {Space-time manifold};
\end{tikzpicture}
\end{document}
below right = 2cm and 1.25cm of B
根据需要适当调整值。第一个值是低于值,第二个值是正确值。
答案3
像这样吗?
您不需要放置每个标签组件,只需使用一个节点,其中包含所有图例。如果您修复了某个节点,text width
TiKZ 将相应地断线,但您也可以使用\\
来断线。
\documentclass[tikz,border=10pt]{standalone}
\usepackage{amssymb}
\usetikzlibrary{positioning}
\begin{document}
\begin{tikzpicture}
\foreach \x/\y/\z in {1/1/9,3.2/1/10,2/1.5/8,1.5/2/6, 2.5/2/7,1.2/2.5/2,2/2.5/4,3.1/2.5/5,2/3/1,2.9/2.9/3}{
\node[circle,fill,inner sep=1.5pt,outer sep=0pt,label={[xshift=-3pt,yshift=2pt,scale=0.7]-60:$\mathrm{P}_{\z}$}] (\z) at (\x,\y){};
}
\node[draw,rectangle,anchor=south west,minimum width=4cm,minimum height=4cm] (A) at (0,0) {};
\node[draw,rectangle,top color=white,bottom color=gray!60,anchor=south west,minimum width=4cm,minimum height=4cm] (B) at (1.3,5) {};
\draw (A.north west) -- (B.north west)
(A.north east) -- (B.north east)
(A.south west) -- (B.south west)
(A.south east) -- (B.south east);
\node (U) at (-1,5) {$\mathrm{U}_1$};
\node at (-1,2) {$\mathrm{U}_2$};
\draw (U.east) edge[bend left] (1.west);
\draw (U.east) edge[bend right] (2.south);
\node[anchor=west, text width=5cm, right=1cm of B.east] {Legend:\\ {\tiny$\blacksquare$} $\mathrm{U}_1$ - instantiated universal \\ {\tiny$\blacksquare$} $\mathrm{U}_2$ - uninstantiated universal\\ {\tiny$\blacksquare$} $\mathrm{P}_1 \ldots \mathrm{P}_2$ - thin particulars\\ {\tiny$\blacksquare$} $\mathrm{P}_3 \ldots \mathrm{P}_{10}$ - bare particulars};
%\node[anchor=west] at (0,-1) {Legend:};
%\node[anchor=west] at (0,-1.5) {{\tiny$\blacksquare$} $\mathrm{U}_1$ - instantiated universal};
%\node[anchor=west] at (0,-2) {{\tiny$\blacksquare$} $\mathrm{U}_2$ - uninstantiated universal};
%\node[anchor=west] at (0,-2.5) {{\tiny$\blacksquare$} $\mathrm{P}_1 \ldots \mathrm{P}_2$ - thin particulars};
%\node[anchor=west] at (0,-3) {{\tiny$\blacksquare$} $\mathrm{P}_3 \ldots \mathrm{P}_{10}$ - bare particulars};
\node[anchor=center,above = 0.1cm of B.north west,font=\bfseries\large] {Space-time manifold};
\end{tikzpicture}
\end{document}
答案4
这是一个解决方案,其中图例相对于绘图边界框的西北角定位:
\documentclass[tikz,border=10pt]{standalone}
\usepackage{amssymb}
\usetikzlibrary{positioning, calc}
\begin{document}
\begin{center}
\begin{tikzpicture}
% Create a scope which includes the drawing (figure) and the legend
\begin{scope}[local bounding box=figure_with_legend]
\foreach \x/\y/\z in {1/1/9, 3.2/1/10, 2/1.5/8, 1.5/2/6, 2.5/2/7, 1.2/2.5/2, 2/2.5/4, 3.1/2.5/5, 2/3/1, 2.9/2.9/3}{
\node[circle,%
fill,%
inner sep=1.5pt,%
outer sep=0pt,%
label={[xshift=-3pt,%
yshift=2pt,%
scale=0.7]-60:$\mathrm{P}_{\z}$}] (\z) at (\x,\y){};
}
\node[draw,%
rectangle,%
anchor=south west,%
minimum width=4cm,%
minimum height=4cm] (A) at (0,0) {};
\node[draw,%
rectangle,%
top color=white,%
bottom color=gray!60,%
anchor=south west,%
minimum width=4cm,%
minimum height=4cm] (B) at (1.3,5) {};
\draw (A.north west) -- (B.north west)
(A.north east) -- (B.north east)
(A.south west) -- (B.south west)
(A.south east) -- (B.south east);
\node (U) at (-1,5) {$\mathrm{U}_1$};
\node at (-1,2) {$\mathrm{U}_2$};
\draw (U.east) edge[bend left] (1.west);
\draw (U.east) edge[bend right] (2.south);
% Place the legend relative of the north east corner of the drawing
\node[anchor=north west,%
align=left] (legend_title) at ($(current bounding box.north east) + (0.5, 0)$) {Legend:};
\node[below=0.20 of legend_title,%
anchor= west] {{\tiny$\blacksquare$} $\mathrm{U}_1$ -- instantiated universal};
\node[below=0.70 of legend_title,%
anchor=west] {{\tiny$\blacksquare$} $\mathrm{U}_2$ -- uninstantiated universal};
\node[below=1.20 of legend_title,%
anchor=west] {{\tiny$\blacksquare$} $\mathrm{P}_1 \ldots \mathrm{P}_2$ -- thin particulars};
\node[below=1.70 of legend_title,%
anchor=west] {{\tiny$\blacksquare$} $\mathrm{P}_3 \ldots \mathrm{P}_{10}$ -- bare particulars};
\end{scope}
% Place the title centered above the drawing and the legend
\node[align=center,%
anchor=center,%
above=of figure_with_legend,%
font=\bfseries\large] {Space-time manifold};
\end{tikzpicture}
\end{center}
\end{document}