
我會先從我最終想要擁有的東西開始。我想要並排放置兩個圖像。我希望 G 點在兩張圖片之間水平均勻,並且我希望兩張圖片的比例相同。 (左側GA之間的距離與右側的距離相同,但它們的旋轉不同)。最後,我希望左圖像 G 位於頁面左半部的中心,右圖像 G 位於頁面右半部的中心。
我的程式碼目前的工作方式是,兩者之間的比例相同(因為它們都在同一個 tikzpicture 中),並且 G 點是水平的,因為它們在程式碼中都位於 y=0 處。
我沒有的是左右居中。由於左側圖像上有更多文本,因此會將兩個圖像推到右側。另外,這有點失敗,因為我手動指定了左右 G 之間的距離。
如果我能夠得到頁面上水平居中的 G 點的中點,我會對兩者之間的固定距離感到滿意。
我也嘗試過做子圖,但它們似乎會擾亂縮放比例,而且我仍然無法讓 G 點在圖形調整大小框中水平居中。
任何人都可以幫助我將其正確居中,而無需過多修改我的程式碼嗎?
編輯:我想出了一個臨時的解決辦法,在 tikzpicture 上畫一條線,該線的中點為 left-G 和 right-G 居中,並且比圖片更寬。但這似乎是一個粗略的解決方法。另外,增加了更多的序言和 \begin{document}。應該是一個工作版本。
EDIT2:另外,如果您看到其他方法來改進我做事的方式,請提出建議。我對使用 Tikz 還很陌生,不知道很多細節。
\documentclass{article}
\usepackage[margin=1in]{geometry}
\usepackage{tikz}
\usepackage{caption,subcaption}
\newcommand\centerarc[6]{
% \centerarc{format}{center_x}{center_y}{radius}{start angle}{end angle};
\draw[#1] ({#2+#4*cos(#5 )},{#3+#4*sin(#5 )}) arc [radius=#4, start angle =#5, end angle=#6];
}
\newcommand\centerofmass{
\tikz[radius=0.4em] {
\fill (0,0) -- ++(0.4em,0) arc [start angle=0,end angle=90] -- ++(0,-0.8em) arc [start angle=270, end angle=180];
\fill [color=white] (0,0) -- ++(0,0.4em) arc [start angle=90,end angle=180] -- ++(0.8em,0) arc [start angle=0, end angle=-90];
\draw (0,0) circle;
}
}
\begin{document}
\begin{figure}[]
\centering
\resizebox{!}{5in}{
\begin{tikzpicture}[scale=0.5,>=stealth]
\draw[line width=8pt, cap=round] (0,0)--(0,0.9);
\draw[line width=8pt, cap=round] (0,0.9)--(0,5.1);
\draw[line width=8pt, cap=round] (0,5.1)--(0,9.9);
\draw[line width=8pt, cap=round] (0,9.9)--(0,18.1);
\filldraw[fill=white] (0,0) circle (0.2);
\filldraw[fill=white] (0,0.9) circle (0.2);
\filldraw[fill=white] (0,5.1) circle (0.2);
\filldraw[fill=white] (0,9.9) circle (0.2);
\filldraw[fill=white] (0,18.1) circle (0.2);
\node [] at (0,14) {\Large\centerofmass};
\node [left] at (-1,0) {Ground Contact Point $\to$ G};
\node [left] at (-1,0.9) {COR of Ankle $\to$ A};
\node [right] at (1,5.1) {K$\gets$ COR of Knee};
\node [left] at (-1,9.9) {COR of Hip $\to$ H};
\node [left] at (-1,18.1) {Crown $\to$ C};
\centerarc{}{0}{0.9}{0.7}{-90}{90};
\node [right] at (0.7,0.9) {$\alpha$};
\centerarc{}{0}{5.1}{0.7}{90}{270};
\node [left] at (-0.7,5.1) {$\theta$};
\centerarc{}{0}{9.9}{0.7}{-90}{90};
\node [right] at (0.7,9.9) {$\beta$};
\draw[line width=2pt, color=red, ->] (0,17)--(0,14);
\node[anchor=west, color=red] at (0.2,17) {$F=2mg$};
\draw[line width=2pt, color=red, ->] (0,-3)--(0,0);
\node[anchor=west, color=red] at (0.2,-3) {$F=2mg$};
\node[] at (0,-5) {(a)};
\def\slide{12}
\draw[line width=8pt, cap=round] (0+\slide,0)--(0+\slide,0.9);
\draw[line width=8pt, cap=round] (0+\slide,0.9)--(2.068+\slide,3.655+0.9);
\draw[line width=8pt, cap=round] (2.065+\slide,3.655+0.9)--(0+\slide,9.9-1.012);
\draw[dashed] (0+\slide,0.9) -- (0+\slide,9.9-1.012);
\draw[line width=8pt, cap=round] (0+\slide,9.9-1.012)--(0+\slide,18.1-1.012);
\filldraw[fill=white] (0+\slide,0) circle (0.2);
\filldraw[fill=white] (0+\slide,0.9) circle (0.2);
\filldraw[fill=white] (2.065+\slide,3.655+0.9) circle (0.2);
\filldraw[fill=white] (0+\slide,9.9-1.012) circle (0.2);
\filldraw[fill=white] (0+\slide,18.1-1.012) circle (0.2);
\node [] at (0+\slide,14-1.012) {\Large\centerofmass};
\node [left] at (-1+\slide,0) {G};
\node [left] at (-1+\slide,0.9) {A};
\node [right] at (1+2.065+\slide,3.655+0.9) {K};
\node [left] at (-1+\slide,9.9-1.012) {H};
\node [left] at (-1+\slide,18.1-1.012) {C};
\centerarc{}{0+\slide}{0.9}{0.7}{-90}{60.5};
\node [right] at (0.7+\slide,0.9) {$\alpha$};
\centerarc{}{2.068+\slide}{3.655+0.9}{0.7}{115}{240};
\node [left] at (-0.7+2.068+\slide,3.655+0.9) {$\theta$};
\centerarc{}{0+\slide}{9.9-1.012}{0.7}{90}{-65}
\node [right] at (0.7+\slide,9.9-1.012) {$\beta$};
\draw[line width=2pt, color=red, ->] (0+\slide,17-1.012)--(0+\slide,14-1.012);
\node[anchor=west, color=red] at (0.2+\slide,17-1.012) {$F=2mg$};
\draw[line width=2pt, color=red, ->] (0+\slide,-3)--(0+\slide,0);
\node[anchor=west, color=red] at (0.2+\slide,-3) {$F=2mg$};
\node[] at (0+\slide,-5) {(b)};
\end{tikzpicture}
}
\caption{\label{fig:stick}(a) Vertical standing position model and notation convention for lab. (b) Points $G,A,H,C$ always stay co-linear during the course of the motion.}
\end{figure}
\end{document}
答案1
有用的東西:
scope
環境。這允許單獨設定scale
//等屬性。red
thick
\paperwidth
、\textwidth
、 和72.27
(這是您的保證金)。xshift
,或一般情況下shift={(1,2)}
。\useasboundingbox
。這使得 TeX 重新考慮 的邊界框(因此大小)tikzpicture
。它類似於smash
或clap
但更加靈活。
\documentclass{article}
\usepackage[margin=1in]{geometry}
\usepackage{tikz}
\usepackage{caption,subcaption}
\newcommand\centerarc[6]{
\draw[#1]({#2+#4*cos(#5)},{#3+#4*sin(#5)})arc[radius=#4,start angle=#5,end angle=#6];}
\newcommand\centerofmass{
\tikz[radius=0.4em]{
\fill(0,0)--++(0.4em,0)arc[start angle=0,end angle=90]--++(0,-0.8em)arc[start angle=270,end angle=180];
\fill[color=white](0,0)--++(0,0.4em)arc[start angle=90,end angle=180]--++(0.8em,0)arc[start angle=0,end angle=-90];\draw(0,0)circle;}}
\begin{document}
\begin{figure}
\noindent
\begin{tikzpicture}[>=stealth]
\useasboundingbox(-.25\paperwidth+72.27,-5)rectangle(0,7);
\begin{scope}[scale=0.5]
\draw[line width=8pt, cap=round] (0,0)--(0,0.9);
\draw[line width=8pt, cap=round] (0,0.9)--(0,5.1);
\draw[line width=8pt, cap=round] (0,5.1)--(0,9.9);
\draw[line width=8pt, cap=round] (0,9.9)--(0,18.1);
\filldraw[fill=white] (0,0) circle (0.2);
\filldraw[fill=white] (0,0.9) circle (0.2);
\filldraw[fill=white] (0,5.1) circle (0.2);
\filldraw[fill=white] (0,9.9) circle (0.2);
\filldraw[fill=white] (0,18.1) circle (0.2);
\node [] at (0,14) {\Large\centerofmass};
\node [left] at (-1,0) {Ground Contact Point $\to$ G};
\node [left] at (-1,0.9) {COR of Ankle $\to$ A};
\node [right] at (1,5.1) {K$\gets$ COR of Knee};
\node [left] at (-1,9.9) {COR of Hip $\to$ H};
\node [left] at (-1,18.1) {Crown $\to$ C};
\centerarc{}{0}{0.9}{0.7}{-90}{90};
\node [right] at (0.7,0.9) {$\alpha$};
\centerarc{}{0}{5.1}{0.7}{90}{270};
\node [left] at (-0.7,5.1) {$\theta$};
\centerarc{}{0}{9.9}{0.7}{-90}{90};
\node [right] at (0.7,9.9) {$\beta$};
\draw[line width=2pt, color=red, ->] (0,17)--(0,14);
\node[anchor=west, color=red] at (0.2,17) {$F=2mg$};
\draw[line width=2pt, color=red, ->] (0,-3)--(0,0);
\node[anchor=west, color=red] at (0.2,-3) {$F=2mg$};
\node[] at (0,-5) {(a)};
\def\slide{12}
\end{scope}
\begin{scope}[scale=0.5,xshift=\paperwidth]
\draw[line width=8pt, cap=round] (0,0)--(0,0.9);
\draw[line width=8pt, cap=round] (0,0.9)--(2.068,3.655+0.9);
\draw[line width=8pt, cap=round] (2.065,3.655+0.9)--(0,9.9-1.012);
\draw[dashed] (0,0.9) -- (0,9.9-1.012);
\draw[line width=8pt, cap=round] (0,9.9-1.012)--(0,18.1-1.012);
\filldraw[fill=white] (0,0) circle (0.2);
\filldraw[fill=white] (0,0.9) circle (0.2);
\filldraw[fill=white] (2.065,3.655+0.9) circle (0.2);
\filldraw[fill=white] (0,9.9-1.012) circle (0.2);
\filldraw[fill=white] (0,18.1-1.012) circle (0.2);
\node [] at (0,14-1.012) {\Large\centerofmass};
\node [left] at (-1,0) {G};
\node [left] at (-1,0.9) {A};
\node [right] at (1+2.065,3.655+0.9) {K};
\node [left] at (-1,9.9-1.012) {H};
\node [left] at (-1,18.1-1.012) {C};
\centerarc{}{0}{0.9}{0.7}{-90}{60.5};
\node [right] at (0.7,0.9) {$\alpha$};
\centerarc{}{2.068}{3.655+0.9}{0.7}{115}{240};
\node [left] at (-0.7+2.068,3.655+0.9) {$\theta$};
\centerarc{}{0}{9.9-1.012}{0.7}{90}{-65}
\node [right] at (0.7,9.9-1.012) {$\beta$};
\draw[line width=2pt, color=red, ->] (0,17-1.012)--(0,14-1.012);
\node[anchor=west, color=red] at (0.2,17-1.012) {$F=2mg$};
\draw[line width=2pt, color=red, ->] (0,-3)--(0,0);
\node[anchor=west, color=red] at (0.2,-3) {$F=2mg$};
\node[] at (0,-5) {(b)};
\end{scope}
\end{tikzpicture}
\caption{\label{fig:stick}(a) Vertical standing position model and notation convention for lab. (b) Points $G,A,H,C$ always stay co-linear during the course of the motion.}
\end{figure}
\end{document}