0

I'll start first with what I want to ultimately have. I want to have the two images side by side. I want the point G to be horizontally even between the two pictures and I want the scale of both images to be the same. (distance between GA on the left is the same distance on the right, but the rotations of these are different). Lastly, I want the left image G to be centered on the left half of the page and the right image G to be centered on the right half of the page.

The way my code currently works is that I have the scale the same between the two (because they're both in the same tikzpicture) and the G points are horizontal because of the fact that they both are at y=0 in the code.

What I don't have is the left-right centering. Because there is more text on the left image it pushes both images to the right. Also, this kinda fails because I specify manually the distance between the G of the left and the right.

I would be content with this fixed distance between the two if I could get the midpoint of the G points horizontally centered on the page.

I've also tried doing sub-figures, but they seem to mess with the scaling and I still can't get the point G to center horizontally in the figure re-size box.

Can anyone help me get this to center correctly without modifying my code too much?

EDIT: I've come up with a temporary work around by making a line the tikzpicture that has the midpoint of left-G and right-G centered and is wider than the pictures. But this seems like a crude workaround. Also, added more of the preamble and \begin{document}. Should be a working version.

EDIT2: Also, if you see other ways to improve the way I did things, please make suggestions. I'm still really new to using Tikz and don't know many of the ins and outs.

\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
    It is better to add a full minimal working example starting with \documentclas... and ending with \end{document}. This way people can see what packages etc you need to get your code to work (but don't add code that is not needed). This makes it much easier for people to help you - and much more likely that they will! – Andrew Sep 21 '14 at 23:56
  • @Andrew I meant to include as much of that as possible. Forgot some. They're added now. – BeaumontTaz Sep 21 '14 at 23:59
  • 1
    Cheers. If no one else replies I'll look at it after lunch...am busy until then. – Andrew Sep 22 '14 at 0:01
  • You should draw with absolute coordinate. As long as you put your TikZ inside a figure, it is impossible to centre TikZ vertically. – Symbol 1 Sep 22 '14 at 2:10
  • @Symbol1 I don't want to center it vertically. I want to center it horizontally. I want it centered <---> in that direction on the page. – BeaumontTaz Sep 22 '14 at 2:11
2

Something useful:

  • scope environment. This allows to set properties such as scale/red/thick separately.
  • \paperwidth, \textwidth, and 72.27(which is your margin).
  • xshift, or ingeneral shift={(1,2)}.
  • \useasboundingbox. This makes TeX reconsider the bounding box (hence the size) of tikzpicture. It is like smash or clap but far more flexible.

\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}
  • That'll do it! Thanks. What is it that scope, and \useboungingbox do, exactly? – BeaumontTaz Sep 22 '14 at 3:00

Your Answer

By clicking “Post Your Answer”, you agree to our terms of service, privacy policy and cookie policy

Not the answer you're looking for? Browse other questions tagged or ask your own question.