6

I have a problem with the text showing the inter-elements spacing, I would like it to be in the same orientation as my structure, is there an easy Tikz solution ?

enter image description here

Code :

\documentclass{article}
\usepackage{tikz}
\usepackage{tikz-3dplot}
\tdplotsetmaincoords{40}{-30}

\begin{document}
\begin{tikzpicture}[tdplot_main_coords]

\def \r{0.5};
\def \d{1.5};
\def \nx{2};
\def \ny{2};
\def \bord{0.11};
\def \hsub{0.1};

\definecolor{cuivre}{rgb}{0.9,0.7,0.4};
\definecolor{ceram}{rgb}{0.92,0.95,0.95};

%masse
\filldraw[fill=gray] (\d-\r-\bord,\d-\r-\bord,-\hsub) 
        --++ (\nx*\d-\r/2,0,0)
        --++ (0,\ny*\d-\r/2,0)
        --++ (-\nx*\d+\r/2,0,0)
        -- cycle; 

%cadre
\filldraw[fill=cuivre] (\d-\r-\bord,\d-\r-\bord,0) 
        --++ (\nx*\d-\r/2,0,0)
        --++ (0,\ny*\d-\r/2,0)
        --++ (-\nx*\d+\r/2,0,0)
        -- cycle; 

%sub1
\filldraw[fill=ceram] (\d-\r-\bord,\d-\r-\bord,0) 
        --++ (0,0,-\hsub)
        --++ (0,\ny*\d-\r/2,0)
        --++ (0,0,\hsub)
        -- cycle;

%sub2
\filldraw[fill=ceram] (\d-\r-\bord,\d-\r-\bord,0) 
        --++ (0,0,-\hsub)
        --++ (\nx*\d-\r/2,0,0)
        --++ (0,0,\hsub)
        -- cycle;

%trous
\foreach \x in {1,...,\nx}{
    \foreach \y in {1,...,\ny}{
        \filldraw[fill=ceram] (\d*\x,\d*\y,0) circle (\r);  
    }
}

\foreach \x in {2,...,\nx}{
    \foreach \y in {2,...,\ny}{
        \filldraw[fill=ceram] (\d*\x-\d/2,\d*\y-\d/2,0) 
        circle (\r);  
    }
}

%espace inter trou 1
\draw[dashed] (\d, \nx*\d,\hsub) --++ (0,1.5,0);
\draw[dashed] (2*\d, \nx*\d,\hsub) --++ (0,1.5,0);
\draw[<->] (\d, \nx*\d+1.5,\hsub) -- (2*\d, \nx*\d+1.5,\hsub) node
[font=\footnotesize,midway, fill=white, anchor=center]{1.5mm};

\end{tikzpicture}
\end{document}
  • It is quite easy, just add it as my answer in this question: tex.stackexchange.com/questions/46682/…, the key is simply to add the new coordinate system to the node as well. However, getting the sizes "correct" while changing coordinate system can be quite tricky. :) – zeroth Jan 26 '14 at 17:57
7

Just add sloped as argument of your last node. above makes the text not cross the line.

\documentclass{article}
\usepackage{tikz}
\usepackage{tikz-3dplot}
\tdplotsetmaincoords{40}{-30}

\begin{document}
\begin{tikzpicture}[tdplot_main_coords]

\def \r{0.5};
\def \d{1.5};
\def \nx{2};
\def \ny{2};
\def \bord{0.11};
\def \hsub{0.1};

\definecolor{cuivre}{rgb}{0.9,0.7,0.4};
\definecolor{ceram}{rgb}{0.92,0.95,0.95};

%masse
\filldraw[fill=gray] (\d-\r-\bord,\d-\r-\bord,-\hsub) 
    --++ (\nx*\d-\r/2,0,0)
    --++ (0,\ny*\d-\r/2,0)
    --++ (-\nx*\d+\r/2,0,0)
    -- cycle; 

%cadre
\filldraw[fill=cuivre] (\d-\r-\bord,\d-\r-\bord,0) 
    --++ (\nx*\d-\r/2,0,0)
    --++ (0,\ny*\d-\r/2,0)
    --++ (-\nx*\d+\r/2,0,0)
    -- cycle; 

%sub1
\filldraw[fill=ceram] (\d-\r-\bord,\d-\r-\bord,0) 
    --++ (0,0,-\hsub)
    --++ (0,\ny*\d-\r/2,0)
    --++ (0,0,\hsub)
    -- cycle;

%sub2
\filldraw[fill=ceram] (\d-\r-\bord,\d-\r-\bord,0) 
    --++ (0,0,-\hsub)
    --++ (\nx*\d-\r/2,0,0)
    --++ (0,0,\hsub)
    -- cycle;

%trous
\foreach \x in {1,...,\nx}{
\foreach \y in {1,...,\ny}{
    \filldraw[fill=ceram] (\d*\x,\d*\y,0) circle (\r);  
}
}

\foreach \x in {2,...,\nx}{
\foreach \y in {2,...,\ny}{
    \filldraw[fill=ceram] (\d*\x-\d/2,\d*\y-\d/2,0) 
    circle (\r);  
}
}

%espace inter trou 1
\draw[dashed] (\d, \nx*\d,\hsub) --++ (0,1.5,0);
\draw[dashed] (2*\d, \nx*\d,\hsub) --++ (0,1.5,0);
\draw[<->] (\d, \nx*\d+1.5,\hsub) -- (2*\d, \nx*\d+1.5,\hsub) node
[font=\footnotesize,midway, fill=white, anchor=center,sloped, above]{1.5mm}; %here's the trick

\end{tikzpicture}
\end{document}

enter image description here

  • 1
    Is it possible to make it in perspective, not only rotated? – Sigur Jan 26 '14 at 16:58
  • Thank you for this answer. As Sigur mentioned previously, I was looking for a real 3D projection, not only a slopped text, but that's a good start. – Thomas Jan 26 '14 at 17:02
  • @Thomas Yes, simply add the projection coordinate system to the node as well, see my comment above. – zeroth Jan 26 '14 at 17:58

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.