4

my figure is long and some part of (in middle) it is not necessary and I want two part come closer to each other (like picture). How it is possible in tikz? enter image description here

\documentclass{article}
\usepackage{tikz}
‎\usetikzlibrary{arrows,calc}‎
‎\RequirePackage{tikzpagenodes}‎
‎\usepackage{xparse}‎‎
‎\NewDocumentCommand\DrawArrows{O{0.5}mmO{-latex}mm}{‎
‎\def\Step{#1}‎
‎\pgfmathsetmacro{\Second}{#5+\Step}‎
‎\foreach \Value [count=\xi] in {#5,\Second,...,#6}‎
  {
  ‎\path[overlay,name path=line\xi]‎ 
    ‎(\Value,100)‎ -- ‎(\Value,-100);‎
  ‎\path[name intersections={of=#2 and line\xi,by={1\xi}}];‎
  ‎\path[name intersections={of=#3 and line\xi,by={2\xi}}];‎
  ‎\ifdim#5pt<\Value pt\relax‎
    ‎\ifdim\Value pt<#6pt\relax‎
    ‎\draw[#4]‎
      ‎(1\xi)‎ -- ‎(2\xi);‎ 
  ‎\fi\fi‎
  }
}
‎\tikzset{%‎
    ‎Cote node/.style={%‎
        ‎midway‎,
        ‎sloped‎,
        ‎fill=white‎,
        ‎inner sep=1.5pt‎,
        ‎outer sep=2pt‎
    ‎}‎,
    ‎Cote arrow/.style={%‎
        ‎<->‎,
        ‎>=latex‎,
        ‎very thin‎
    }
}
‎\makeatletter‎
‎\NewDocumentCommand{\Cote}{%‎
    ‎s       % cotation avec les flèches à l'extérieur‎
    ‎D<>{1.5pt} % offset des traits‎
    ‎O{.75cm}    % offset de cotation‎
    ‎m       % premier point‎
    ‎m       % second point‎
    ‎m       % étiquette‎
    ‎D<>{o}  % () coordonnées‎ -‎> angle‎
            % ‎h‎ -‎> horizontal‎,
            % ‎v‎ -‎> vertical‎
            % ‎o or what ever‎ -‎> oblique‎
    ‎O{}     % parametre du tikzset‎
    }{%
    ‎{\tikzset{#8}‎
    ‎\coordinate (@1) at #4 ;‎
    ‎\coordinate (@2) at #5 ;‎
‎\if #7v % Cotation verticale‎
    ‎\coordinate (@0) at ($($#4!.5!#5$)‎ + ‎(#3,0)$) ;‎ 
    ‎\coordinate (@4) at (@0|-@1) ;‎
    ‎\coordinate (@5) at (@0|-@2) ;‎
‎\else‎
‎\if #7h % Cotation horizontale‎
    ‎\coordinate (@0) at ($($#4!.5!#5$)‎ + ‎(0,#3)$) ;‎ 
    ‎\coordinate (@4) at (@0-|@1) ;‎
    ‎\coordinate (@5) at (@0-|@2) ;‎
‎\else % cotation encoche‎
‎\ifnum\pdfstrcmp{\unexpanded\expandafter{\@car#7\@nil}}{(}=\z@‎
    ‎\coordinate (@5) at ($#7!#3!#5$) ;‎
    ‎\coordinate (@4) at ($#7!#3!#4$) ;‎
‎\else % cotation oblique‎    
    ‎\coordinate (@5) at ($#5!#3!90:#4$) ;‎
    ‎\coordinate (@4) at ($#4!#3!-90:#5$) ;‎
‎\fi\fi\fi‎

‎\draw[very thin,shorten >= #2,shorten <=‎ -‎2*#2] (@4)‎ -- ‎#4 ;‎
‎\draw[very thin,shorten >= #2,shorten <=‎ -‎2*#2] (@5)‎ -- ‎#5 ;‎

‎\IfBooleanTF #1 {% avec étoile‎
‎\draw[Cote arrow,-] (@4)‎ -- ‎(@5)‎
    ‎node[Cote node] {#6\strut};‎
‎\draw[Cote arrow,<-] (@4)‎ -- ‎($(@4)!-6pt!(@5)$) ;‎   
‎\draw[Cote arrow,<-] (@5)‎ -- ‎($(@5)!-6pt!(@4)$) ;‎   
}{% ‎sans étoile‎
‎\ifnum\pdfstrcmp{\unexpanded\expandafter{\@car#7\@nil}}{(}=\z@‎
    ‎\draw[Cote arrow] (@5) to[bend right]‎
        ‎node[Cote node] {#6\strut} (@4) ;‎
‎\else‎
‎\draw[Cote arrow] (@4)‎ -- ‎(@5)‎
    ‎node[Cote node] {#6\strut};‎
‎\fi‎
}}
}
\begin{document}
\begin{tikzpicture}
   ‎\coordinate (O) at (0,0);‎‎
        \Cote{(2,-.5)}{(2,.5)}{‎$‎b(x)‎$‎}[ Cote node/.append style={right,rotate=-90}];
\Cote[1cm]{(0,0)}{(4,0)}{‎$‎L‎$‎}  ;
 ‎\fill[blue!30,opacity=0.65] (0,0.15)..controls(2,.55).. (4,0.4)--(4,-0.4) ..controls(2,-.55)..  (0,-0.15)‎ -- ‎cycle;‎‎‎
  ‎\draw[thick] (0,0.15)..controls(2,.55).. (4,0.4)--(4,-0.4) ..controls(2,-.55)..  (0,-0.15)‎ -- ‎cycle;‎‎‎
         ‎\draw[->] (O)‎ -- +‎+(0,1.1) node[right] {$y$};‎
        ‎\draw[->] (O)‎ -- +‎+(1,0) node[above] {$x$};‎‎
  ‎\end{tikzpicture}‎
\end{document}
  • i don't recognize \draw[axis]. Where does this come from? – John Kormylo Sep 16 '15 at 21:25
  • Also, when I copied your code I got a bunch of oddball invisible characters. I wound up having to retype the whole thing. – John Kormylo Sep 16 '15 at 22:07
3

The easiest way is to fill white over the original image.

To move the two parts closer together, I drew it twice using clipping rectangles. The left part is clipped in the first scope and the right part is clipped in the second scope.

Note, if you shift them too close together the white fill may overlap some of the image.

\documentclass{article}
\usepackage{tikz}
\begin{document}
\begin{tikzpicture}
\begin{scope}
  \clip (-.2,-1.2) rectangle (1.6,1.2);% clip left part
  \path[fill=blue!30,opacity=0.65,draw=black,thick] (0,0.15) ..controls(2,.55).. (4,0.4)--
    (4,-0.4) ..controls(2,-.55).. (0,-0.15) -- cycle;
  \fill[white] (1.5,1) ..controls(1.6,.6) and (1.2,-.5).. (1.5,-1)--
    (3.5,-1) ..controls(3.2,-.5) and (3.6,.6).. (3.5,1) -- cycle;
  \draw[black,very thick] (1.5,1) ..controls(1.6,.6) and (1.2,-.5).. (1.5,-1);
  \draw[black,very thick] (3.5,-1) ..controls(3.2,-.5) and (3.6,.6).. (3.5,1);
  \coordinate (O) at (0,0);
  \draw[->] (O) -- ++(0,1.1) node[right] {$y$};
  \draw[->] (O) -- ++(1,0) node[above] {$x$};
\end{scope}
\begin{scope}[xshift=-1.5cm]
  \clip (3.2,-1.2) rectangle (4.2,1.2);% clip right part
  \path[fill=blue!30,opacity=0.65,draw=black,thick] (0,0.15) ..controls(2,.55).. (4,0.4)--
    (4,-0.4) ..controls(2,-.55).. (0,-0.15) -- cycle;
  \fill[white] (1.5,1) ..controls(1.6,.6) and (1.2,-.5).. (1.5,-1)--
    (3.5,-1) ..controls(3.2,-.5) and (3.6,.6).. (3.5,1) -- cycle;
  \draw[black,very thick] (1.5,1) ..controls(1.6,.6) and (1.2,-.5).. (1.5,-1);
  \draw[black,very thick] (3.5,-1) ..controls(3.2,-.5) and (3.6,.6).. (3.5,1);
  \coordinate (O) at (0,0);
  \draw[->] (O) -- ++(0,1.1) node[right] {$y$};
  \draw[->] (O) -- ++(1,0) node[above] {$x$};
\end{scope}
\end{tikzpicture}
\end{document}

cutout and shifted

  • tank uoy, I want to move the parts closer in tikz? how t is possible? – sayros Sep 17 '15 at 3:34
  • Okay, I modified the solution. – John Kormylo Sep 17 '15 at 4:09

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.