7

Newbie here. Could anyone tell me how to (1) shade a line and (2) how to offset a line?

I have a very simple graph,enter image description here

This is a mesh used in finite element analysis, I have already used tikz to build a mesh and I am satisfied with it. But now I want to improve it! The shade effect represents it is a "fixed wall", and the second layer grid line should be offset of the first wall layer line.

Here is my scripts of generating the grids. (You dont need to follow this scripts. You can disregard this scripts, a two layer grid lines is enough for me.)

\begin{tikzpicture}
[
    scale=1,
    every node/.style={scale=0.5},
    x=0.1cm,y=0.1cm
]
\usetikzlibrary{calc}

\usetikzlibrary{arrows,patterns}


\draw ( 0.0, 0.0)--( 8.0, 0.0)--(16.0, 0.0)--(22.0, 3.0)--(26.5, 6.5)--(30.0,14.5)--(33.0,16.2)--(36.0,14.5)--(39.5, 6.5)--(44.0, 3.0)--(50.0, 0.0)--(58.0, 0.0)--(66.0, 0.0);
\draw (0.0,8.5)--(8.0,8.8)--(14.2,9.1)--(17.9,10.0)--(22.5,12.0)--(27.6,17.6)--(32.2,19.7)--(38.4,17.6)--(43.5,12.0)--(48.1,10.0)--(51.8, 9.1)--(58.0, 8.8)--(66.0,8.5);
\draw (0.0,17.3)--(6.2,18.5)--(11.2,18.8)--(14.6,19.0)--(21.9,19.9)--(28.4,22.5)--(35.0,25.0)--(37.6,22.5)--(44.1,19.9)--(51.4,19.0)--(54.8,18.8)--(59.8,18.5)--(66.0,17.3);
\draw (0.0,30.0)--(6.2,30.0)--(11.2,30.0)--(14.6,30.0)--(21.9,30.0)--(28.4,30.0)--(35.0,30.0)--(37.6,30.0)--(44.1,30.0)--(51.4,30.0)--(54.8,30.0)--(59.8,30.0)--(66.0,30.0);
\draw ( 0.0, 0.0)--( 0.0, 8.5)--( 0.0,17.3)--( 0.0,30.0);
\draw ( 8.0, 0.0)--( 8.0, 8.8)--( 6.2,18.5)--( 6.2,30.0);
\draw (16.0, 0.0)--(14.2, 9.1)--(11.2,18.8)--(11.2,30.0);
\draw (22.0, 3.0)--(17.9,10.0)--(14.6,19.0)--(14.6,30.0);
\draw (26.5, 6.5)--(22.5,12.0)--(21.9,19.9)--(21.9,30.0);
\draw (30.0,14.5)--(27.6,17.6)--(28.4,22.5)--(28.4,30.0);
\draw (33.0,16.2)--(32.2,19.7)--(35.0,25.0)--(35.0,30.0);
\draw (36.0,14.5)--(38.4,17.6)--(37.6,22.5)--(37.6,30.0);
\draw (39.5, 6.5)--(43.5,12.0)--(44.1,19.9)--(44.1,30.0);
\draw (44.0, 3.0)--(48.1,10.0)--(51.4,19.0)--(51.4,30.0);
\draw (50.0, 0.0)--(51.8, 9.1)--(54.8,18.8)--(54.8,30.0);
\draw (58.0, 0.0)--(58.0, 8.8)--(59.8,18.5)--(59.8,30.0);
\draw (66.0, 0.0)--(66.0, 8.5)--(66.0,17.3)--(66.0,30.0);



\end{tikzpicture}
  • For the shaded line: tex.stackexchange.com/questions/13933/… – Jake Apr 26 '13 at 20:02
  • While code snippets are useful in explanations, it is always best to compose a fully compilable MWE that illustrates the problem including the \documentclass and the appropriate packages so that those trying to help don't have to recreate it. – Peter Grill Apr 27 '13 at 3:47
4

With clipping:

Code

\documentclass[tikz,border=3mm]{standalone}

\begin{document}

\newcommand{\mypath}{(0.0,0.0) -- ( 8.0, 0.0) -- (16.0, 0.0) -- (22.0, 3.0) -- (26.5,6.5) -- (30.0,14.5) -- (33.0,16.2) -- (36.0,14.5) -- (39.5,6.5) -- (44.0,3.0) -- (50.0,0.0) -- (58.0,0.0) -- (66.0, 0.0)}

\begin{tikzpicture}
[   scale=0.1,
]
    \draw \mypath;
    \draw (0.0,8.5) -- (8.0,8.8) -- (14.2,9.1) -- (17.9,10.0) -- (22.5,12.0) -- (27.6,17.6) -- (32.2,19.7) -- (38.4,17.6) -- (43.5,12.0) -- (48.1,10.0) -- (51.8, 9.1) -- (58.0, 8.8) -- (66.0,8.5);
    \draw (0.0,17.3) -- (6.2,18.5) -- (11.2,18.8) -- (14.6,19.0) -- (21.9,19.9) -- (28.4,22.5) -- (35.0,25.0) -- (37.6,22.5) -- (44.1,19.9) -- (51.4,19.0) -- (54.8,18.8) -- (59.8,18.5) -- (66.0,17.3);
    \draw (0.0,30.0) -- (6.2,30.0) -- (11.2,30.0) -- (14.6,30.0) -- (21.9,30.0) -- (28.4,30.0) -- (35.0,30.0) -- (37.6,30.0) -- (44.1,30.0) -- (51.4,30.0) -- (54.8,30.0) -- (59.8,30.0) -- (66.0,30.0);
    \draw ( 0.0, 0.0) -- ( 0.0, 8.5) -- ( 0.0,17.3) -- ( 0.0,30.0);
    \draw ( 8.0, 0.0) -- ( 8.0, 8.8) -- ( 6.2,18.5) -- ( 6.2,30.0);
    \draw (16.0, 0.0) -- (14.2, 9.1) -- (11.2,18.8) -- (11.2,30.0);
    \draw (22.0, 3.0) -- (17.9,10.0) -- (14.6,19.0) -- (14.6,30.0);
    \draw (26.5, 6.5) -- (22.5,12.0) -- (21.9,19.9) -- (21.9,30.0);
    \draw (30.0,14.5) -- (27.6,17.6) -- (28.4,22.5) -- (28.4,30.0);
    \draw (33.0,16.2) -- (32.2,19.7) -- (35.0,25.0) -- (35.0,30.0);
    \draw (36.0,14.5) -- (38.4,17.6) -- (37.6,22.5) -- (37.6,30.0);
    \draw (39.5, 6.5) -- (43.5,12.0) -- (44.1,19.9) -- (44.1,30.0);
    \draw (44.0, 3.0) -- (48.1,10.0) -- (51.4,19.0) -- (51.4,30.0);
    \draw (50.0, 0.0) -- (51.8, 9.1) -- (54.8,18.8) -- (54.8,30.0);
    \draw (58.0, 0.0) -- (58.0, 8.8) -- (59.8,18.5) -- (59.8,30.0);
    \draw (66.0, 0.0) -- (66.0, 8.5) -- (66.0,17.3) -- (66.0,30.0);
    \begin{scope}
        \clip \mypath |- (0,-2) -- cycle;
        \draw[line width=1mm,densely dotted] \mypath;
    \end{scope}
\end{tikzpicture}

\end{document}

Output

enter image description here


With decoration:

Code

\documentclass[tikz,border=3mm]{standalone}
\usetikzlibrary{decorations.pathreplacing}

\begin{document}

\newcommand{\mypath}{(0.0,0.0) -- ( 8.0, 0.0) -- (16.0, 0.0) -- (22.0, 3.0) -- (26.5,6.5) -- (30.0,14.5) -- (33.0,16.2) -- (36.0,14.5) -- (39.5,6.5) -- (44.0,3.0) -- (50.0,0.0) -- (58.0,0.0) -- (66.0, 0.0)}

\begin{tikzpicture}
[   scale=0.1,
]
    \draw \mypath;
    \draw (0.0,8.5) -- (8.0,8.8) -- (14.2,9.1) -- (17.9,10.0) -- (22.5,12.0) -- (27.6,17.6) -- (32.2,19.7) -- (38.4,17.6) -- (43.5,12.0) -- (48.1,10.0) -- (51.8, 9.1) -- (58.0, 8.8) -- (66.0,8.5);
    \draw (0.0,17.3) -- (6.2,18.5) -- (11.2,18.8) -- (14.6,19.0) -- (21.9,19.9) -- (28.4,22.5) -- (35.0,25.0) -- (37.6,22.5) -- (44.1,19.9) -- (51.4,19.0) -- (54.8,18.8) -- (59.8,18.5) -- (66.0,17.3);
    \draw (0.0,30.0) -- (6.2,30.0) -- (11.2,30.0) -- (14.6,30.0) -- (21.9,30.0) -- (28.4,30.0) -- (35.0,30.0) -- (37.6,30.0) -- (44.1,30.0) -- (51.4,30.0) -- (54.8,30.0) -- (59.8,30.0) -- (66.0,30.0);
    \draw ( 0.0, 0.0) -- ( 0.0, 8.5) -- ( 0.0,17.3) -- ( 0.0,30.0);
    \draw ( 8.0, 0.0) -- ( 8.0, 8.8) -- ( 6.2,18.5) -- ( 6.2,30.0);
    \draw (16.0, 0.0) -- (14.2, 9.1) -- (11.2,18.8) -- (11.2,30.0);
    \draw (22.0, 3.0) -- (17.9,10.0) -- (14.6,19.0) -- (14.6,30.0);
    \draw (26.5, 6.5) -- (22.5,12.0) -- (21.9,19.9) -- (21.9,30.0);
    \draw (30.0,14.5) -- (27.6,17.6) -- (28.4,22.5) -- (28.4,30.0);
    \draw (33.0,16.2) -- (32.2,19.7) -- (35.0,25.0) -- (35.0,30.0);
    \draw (36.0,14.5) -- (38.4,17.6) -- (37.6,22.5) -- (37.6,30.0);
    \draw (39.5, 6.5) -- (43.5,12.0) -- (44.1,19.9) -- (44.1,30.0);
    \draw (44.0, 3.0) -- (48.1,10.0) -- (51.4,19.0) -- (51.4,30.0);
    \draw (50.0, 0.0) -- (51.8, 9.1) -- (54.8,18.8) -- (54.8,30.0);
    \draw (58.0, 0.0) -- (58.0, 8.8) -- (59.8,18.5) -- (59.8,30.0);
    \draw (66.0, 0.0) -- (66.0, 8.5) -- (66.0,17.3) -- (66.0,30.0);
    \draw[decoration={ticks,segment length=0.25mm,amplitude=0.3mm,raise=-0.25mm},decorate] \mypath;

\end{tikzpicture}

\end{document}

Output

enter image description here


With inclinded lines:

Code

\documentclass[tikz,border=3mm]{standalone}
\usetikzlibrary{decorations.pathreplacing}

\begin{document}

\newcommand{\mypath}{(0.0,0.0) -- ( 8.0, 0.0) -- (16.0, 0.0) -- (22.0, 3.0) -- (26.5,6.5) -- (30.0,14.5) -- (33.0,16.2) -- (36.0,14.5) -- (39.5,6.5) -- (44.0,3.0) -- (50.0,0.0) -- (58.0,0.0) -- (66.0, 0.0)}

\begin{tikzpicture}
[   scale=0.1,
]
    \draw \mypath;
    \draw (0.0,8.5) -- (8.0,8.8) -- (14.2,9.1) -- (17.9,10.0) -- (22.5,12.0) -- (27.6,17.6) -- (32.2,19.7) -- (38.4,17.6) -- (43.5,12.0) -- (48.1,10.0) -- (51.8, 9.1) -- (58.0, 8.8) -- (66.0,8.5);
    \draw (0.0,17.3) -- (6.2,18.5) -- (11.2,18.8) -- (14.6,19.0) -- (21.9,19.9) -- (28.4,22.5) -- (35.0,25.0) -- (37.6,22.5) -- (44.1,19.9) -- (51.4,19.0) -- (54.8,18.8) -- (59.8,18.5) -- (66.0,17.3);
    \draw (0.0,30.0) -- (6.2,30.0) -- (11.2,30.0) -- (14.6,30.0) -- (21.9,30.0) -- (28.4,30.0) -- (35.0,30.0) -- (37.6,30.0) -- (44.1,30.0) -- (51.4,30.0) -- (54.8,30.0) -- (59.8,30.0) -- (66.0,30.0);
    \draw ( 0.0, 0.0) -- ( 0.0, 8.5) -- ( 0.0,17.3) -- ( 0.0,30.0);
    \draw ( 8.0, 0.0) -- ( 8.0, 8.8) -- ( 6.2,18.5) -- ( 6.2,30.0);
    \draw (16.0, 0.0) -- (14.2, 9.1) -- (11.2,18.8) -- (11.2,30.0);
    \draw (22.0, 3.0) -- (17.9,10.0) -- (14.6,19.0) -- (14.6,30.0);
    \draw (26.5, 6.5) -- (22.5,12.0) -- (21.9,19.9) -- (21.9,30.0);
    \draw (30.0,14.5) -- (27.6,17.6) -- (28.4,22.5) -- (28.4,30.0);
    \draw (33.0,16.2) -- (32.2,19.7) -- (35.0,25.0) -- (35.0,30.0);
    \draw (36.0,14.5) -- (38.4,17.6) -- (37.6,22.5) -- (37.6,30.0);
    \draw (39.5, 6.5) -- (43.5,12.0) -- (44.1,19.9) -- (44.1,30.0);
    \draw (44.0, 3.0) -- (48.1,10.0) -- (51.4,19.0) -- (51.4,30.0);
    \draw (50.0, 0.0) -- (51.8, 9.1) -- (54.8,18.8) -- (54.8,30.0);
    \draw (58.0, 0.0) -- (58.0, 8.8) -- (59.8,18.5) -- (59.8,30.0);
    \draw (66.0, 0.0) -- (66.0, 8.5) -- (66.0,17.3) -- (66.0,30.0);
    \draw[decoration={border,segment length=0.3mm,amplitude=0.8mm,mirror,angle=45},decorate] \mypath;
\end{tikzpicture}

\end{document}

Output

enter image description here

  • Couldn't the decoration lines be inclined? – Daniel May 8 '13 at 18:59
  • Yes, just add angle=<degrees> to the decoration. – Tom Bombadil May 8 '13 at 19:17
  • You mean this \draw[decoration={ticks,segment length=0.5mm,amplitude=0.9mm,raise=-1mm,angle=50},decorate] \mypath;? Nothing happens... – Daniel May 9 '13 at 3:37
  • 1
    You'll need the border decoration instead of the ticks decoration, see the last update. – Tom Bombadil May 9 '13 at 11:41

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.