3

I am new in TikZ (but not in LaTeX). I am trying to create the following free body diagram. enter image description here

Here is my effort so far (nothing special:-!)).

\begin{tikzpicture}
\filldraw[lightgray, very thick] (0,0)rectangle (3,0.5);
\draw[->, thick](0,-1)--(0,0);
\draw[->, thick](1,-1)--(1,0);
\draw[->, thick](2,-1)--(2,0);
\draw[->, thick](3,-1)--(3,0);
\draw[->, thick](0,1.25)--(0,0.5);
\draw[->, thick](1,1.25)--(1,0.5);
\draw[->, thick](2,1.25)--(2,0.5);
\draw[->, thick](3,1.25)--(3,0.5);
\draw[->,very thick](1.5,0)--(1.5,-2);
\node at (2,-2.3) {$w=mg$};
\node at (2,1.6) {$P_{\rm{atm}}$};
\node at (2,-1.4) {$P_{\rm{gas}}$};
\end{tikzpicture}

a) How can achieve this shady gray effect? b) How can I modify the arrow heads? c) How can I modify the perimeter of the rectangle (make it visible, black and thick)?

I have to add that I work with exam document class, \documentclass[12pt,addpoints]{exam}.

Thank you very much in advance.

  • Welcome to the world of TikZ. There is a library shadings, which you can use. There is also a library for the arrows (arrows) and the rectangle can be controlled by its properties draw and line width. – TeXnician Feb 8 '17 at 15:02
  • Thanks. I am actually aware of the arrows library. But with the exam class I got error messages. May be I did something wrong. – Dimitris Feb 8 '17 at 15:04
  • Try \tikzset{>={stealth}}. – TeXnician Feb 8 '17 at 15:05
  • I got no error with exam class, so you have to post a MWE. – TeXnician Feb 8 '17 at 15:11
  • Ok, thanks again! I did something wrong probably. I will check it again. – Dimitris Feb 8 '17 at 15:12
7

One version of a shady gray effect is applying a radial shading to the picture. That can be done setting the inner color and outer color properties (no library required).

For the arrow tips you can use the library arrows and \tikzset{>={stealth}}. Last but not least you can apply keys such as thick etc. to your \filldraw macro. Maybe you want to have a look at the property line width.

your picture

Update: Following the great suggestion by JLDiaz in the comments you probably want to replace the inner color/outer color approach with the more appropriate (for rectangles) left color=gray, right color=gray, middle color=white.

picture 2

\documentclass[addpoints]{exam}

\usepackage{tikz}
\usetikzlibrary{arrows}
\tikzset{>={stealth}}

\begin{document}
\begin{tikzpicture}
\filldraw[inner color=white,outer color=lightgray, thick] (0,0)rectangle (3,0.5);
\draw[->, thick] (0,-1)--(0,0);
\draw[->, thick](1,-1)--(1,0);
\draw[->, thick](2,-1)--(2,0);
\draw[->, thick](3,-1)--(3,0);
\draw[->, thick](0,1.25)--(0,0.5);
\draw[->, thick](1,1.25)--(1,0.5);
\draw[->, thick](2,1.25)--(2,0.5);
\draw[->, thick](3,1.25)--(3,0.5);
\draw[->,very thick](1.5,0)--(1.5,-2);
\node at (2,-2.3) {$W=mg$};
\node at (2,1.6) {$P_{\rm{atm}}$};
\node at (2,-1.4) {$P_{\rm{gas}}$};
\end{tikzpicture}
\end{document}
  • 1
    I think that a cylindrical shade is more akin to the OP picture. You can achieve it with \filldraw[left color=gray, right color=gray, middle color=white, thick]. – JLDiaz Feb 8 '17 at 15:29
  • @CarLaTeX You're welcome ;) – TeXnician Feb 8 '17 at 15:38
  • @TeXnician: Thank you very much for the nice answer! – Dimitris Feb 8 '17 at 15:43

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.