我最近开始使用 Tikz,尽管查找了类似的问题,但我无法解决这个问题。我尝试将图片从 1 缩放到 1.2 或更高,居中不起作用。我希望有人能帮助我。提前谢谢!
\documentclass{article}
\usepackage{tikz,tikz-3dplot}
\tdplotsetmaincoords{80}{45}
\tdplotsetrotatedcoords{-90}{180}{-90}
\begin{document}
\begin{figure}[!h]
\centering
\tikzset{surface/.style={draw=blue!70!black, fill=blue!40!white, fill opacity=.6}}
\newcommand{\coneback}[4][]{
\draw[canvas is xy plane at z=#2, #1] (45-#4:#3) arc (45-#4:225+#4:#3) -- (O) --cycle;
}
\newcommand{\conefront}[4][]{
\draw[canvas is xy plane at z=#2, #1] (45-#4:#3) arc (45-#4:-135+#4:#3) -- (O) --cycle;
}
\begin{tikzpicture}[tdplot_main_coords, grid/.style={help lines,blue!40!white,opacity=0.2},scale=1.2]
\coordinate (O) at (0,0,0);
\fill[blue!40!white,opacity=0.5] (-4,-4,0) -- (-4,4,0) -- (4,4,0) -- (4,-4,0) -- cycle;
\foreach \x in {-4,...,4}
\foreach \y in {-4,...,4}
{
\draw[grid] (\x,-4) -- (\x,4);
\draw[grid] (-4,\y) -- (4,\y);
}
\coneback[surface]{-3}{2}{-12}
\conefront[surface]{-3}{2}{-12}
\draw[->] (-4,0,0) -- (4,0,0) {};
\draw[->] (0,-4,0) -- (0,4,0) {};
\coneback[surface]{3}{2}{12}
\draw[-,dashed] (0,0,-2.65) -- (0,0,2.65) node[above] {};
\draw[-,dashed] (0,0,-4) -- (0,0,-3.35) node[above] {};
\draw[->,dashed] (0,0,3.35) -- (0,0,4) node[above] {$time$};
\conefront[surface]{3}{2}{12}
\fill (4,0,2) circle (2pt) node[above right] {$C$};
\fill (0,0,0) circle (2pt) {};
\fill (-0.5,-0.85,2.2) circle (2pt) node[above left] {$A$};
\fill (1.3,0.5,2) circle (2pt) node[above left] {$B$};
\draw[->,red] (0,0,0) -- (4,0,2) node[below, pos=0.6, rotate=26.5651,scale=0.75,black] {$\textbf{spacelike vector}$};
\draw[->,red] (0,0,0) -- (1.3,0.5,2) node[below, pos=0.6, rotate=55.1459,scale=0.75,black] {$\textbf{lightlike vector}$};
\draw[->,red] (0,0,0) -- (-0.5,-0.85,2.2) node[above, pos=0.57, rotate=-65.8557,scale=0.75,black] {$\textbf{timelike vector}$};
\node[black] at (0,0,3) {$Future\,\,Light\,\,Cone$};
\node[black] at (0,0,-3) {$Past\,\,Light\,\,Cone$};
\node[black] at (0,0.05,0.3) {$O$};
\node[black] at (0,4.7,0) {$space$};
\node[black] at (5,-0.3,0) {$space$};
\end{tikzpicture}
\caption{Light Cone in 2d Space plus a Time Dimension}
\label{cone}
\end{figure}
\end{document}
答案1
居中确实有效。您没有在文档中指定边距的大小,因此当您缩放图片时,LaTeX 会尝试将其居中,但图表无法进入左边距。显然,您不希望图片比页面本身更宽。因此我认为您需要做三件事:
- 确定页面大小和文本宽度。
- 确定图片占据文本宽度的哪一部分。
- 相应缩放。
这全都是个人品味的问题,但我喜欢图片的宽度和文本宽度的黄金比例。
我在你的代码前言中添加了以下几行:
\usepackage{geometry}
\geometry{
a4paper,
total={170mm,257mm},
left=20mm,
top=20mm,
}
简而言之,您的问题不是 tikz 包的问题,而是页面几何形状和图片在页面上的定位问题。这里需要您做出一些决定。其余部分运行顺利。