1

I am trying to draw the following figure: enter image description here

Please observe that the label "h" has a very large "white" box around it. I would like to reduce the size of this box so that the figure looks better.

How do I do this?

Here is the TiKz code:

\documentclass[12pt]{standalone}
\usepackage{pgfplots}
\usepackage{tikz}
\usepackage{tikz-3dplot}
\usetikzlibrary{calc,3d,decorations.markings, backgrounds, positioning,intersections,shapes}

\begin{document}
\begin{tikzpicture}[scale=1.6]
  % top
  \coordinate (A) at (1.1, -1.3); 
  \coordinate (B) at (2.2, -0.2); 
  \coordinate (C) at (3.3,-0.4); 
  \coordinate (D) at (4.35,-0.9);
  \coordinate (E) at (3.3,-1.65);

  \node[anchor=east] at (A) {\scriptsize $A$};
  \node[anchor=south, yshift=-1mm] at (B) {\scriptsize $B$};
  \node[anchor=west, yshift=1mm] at (C) {\scriptsize $C$};
  \node[anchor=north west, xshift=-1mm] at (D) {\scriptsize $D$};
  \node[anchor=north, yshift=0.5mm] at (E) {\scriptsize $E$};


  \draw[line width=1 ] (A)--(B)--(C)--(D)--(E)--cycle;
  \draw[line width=1 ] (C)--(E);

  % midpoint between C and D
  \coordinate (M) at ($(D)!0.5!(E)$);
  \node[anchor=north west, xshift=-1mm] at (M) {\scriptsize $M$};

  \coordinate (F) at (2.6,-0.8);
  \draw[line width=1, dashed ] (B)--(F);
  \draw[line width=1, dashed ] (D)--(F);
  \draw[line width=1, dashed ] (A)--(F);

  % midpoint between A and F 
  \coordinate (N) at ($(A)!0.5!(F)$);
  \node[anchor=south east, xshift=2mm, yshift=-4mm] at (N) {\scriptsize $N$};

  \draw[line width=1, fill=yellow, opacity=0.5 ] (B)--(C)--(M)--(N)--cycle;

  \coordinate (O) at ($(N)!0.2!(M)$);
  \coordinate (P) at ($(N)!0.7!(M)$);

  \draw[dotted] (C)--(P) node[anchor=north] {\scriptsize $P$};
  \draw[dotted] (B)--(O) node[anchor=north] {\scriptsize $O$};

  \coordinate (Cs) at ($(C)!0.1!(B)$);
  \coordinate (Ps) at ($(P)!0.1!(O)$);

  \draw[] (Cs) -- (Ps) node [midway, color=black, fill=white] {\tiny $h$};
\end{tikzpicture}
\end{document}

Thanks.

  • 2
    Wouldn't node [inner sep=0mm,midway, color=black, fill=white] work ? – Bibi Dec 7 '15 at 17:38
2

This is simply: just reduce inner separation: inner sep=1pt, i.e. instead of

\draw[] (Cs) -- (Ps) node [midway, color=black, fill=white] {\tiny $h$};

use

\draw (Cs) -- node [fill=yellow!50,inner sep=1pt] {\tiny $h$} (Ps);

Remark: if you change

`\begin{tikzpicture}[scale=1.6]

to:

\begin{tikzpicture}[scale=1.6,
    font=\scriptsize]

you can erase all \scriptsize in nodes content ...

Upgrade: I slightly reorder your MWE. Maybe you will find this useful:

\documentclass[12pt]{standalone}
\usepackage{pgfplots}
\usepackage{tikz}
\usepackage{tikz-3dplot}
\usetikzlibrary{calc,3d,decorations.markings, backgrounds, positioning,intersections,shapes}

\begin{document}
\begin{tikzpicture}[scale=1.6,
every label/.style = {inner sep=2pt,font=\scriptsize}
                    ]
% top
  \coordinate[label=below:$A$] (A) at (1.1, -1.3);
  \coordinate[label=above:$B$] (B) at (2.2, -0.2);
  \coordinate[label=above:$C$] (C) at (3.3,-0.4);
  \coordinate[label=below:$D$] (D) at (4.35,-0.9);
  \coordinate[label=below:$E$] (E) at (3.3,-1.65);
  \coordinate (F) at (2.6,-0.8);
% midpoint between C and D
  \coordinate[label={[yshift=1mm]below right:$M$}] (M) at ($(D)!0.5!(E)$);
% midpoint between A and F
  \coordinate[label=below:$N$] (N) at ($(A)!0.5!(F)$);
%
  \coordinate[label=below:$O$] (O) at ($(N)!0.2!(M)$);
  \coordinate[label={[xshift=-1pt]below:$P$}] (P) at ($(N)!0.7!(M)$);

\begin{scope}[line width=1pt]
  \draw (A)--(B)--(C)--(D)--(E)--cycle;
\coordinate (F) at (2.6,-0.8);
  \draw[dashed] (B)--(F);
  \draw[dashed] (D)--(F);
  \draw[dashed] (A)--(F);

  \draw[fill=yellow, opacity=0.5] (B)--(C)--(M)--(N)--cycle;
  \draw (C)--(E);
\end{scope}

  \draw[dotted] (C)--(P)    (B)--(O);

  \coordinate (Cs) at ($(C)!0.1!(B)$);
  \coordinate (Ps) at ($(P)!0.1!(O)$);

  \draw (Cs) -- node [fill=yellow!50,inner sep=1pt] {\tiny $h$} (Ps);
\end{tikzpicture}
\end{document}

which gives:

enter image description here

  • 1
    @HermanJaramillo, see upgrade of my answer. – Zarko Dec 7 '15 at 18:06
  • It looks beautiful. I also appreciate you telling me how to factor out the font size. That saves me lots of typing. – Herman Jaramillo Dec 7 '15 at 21:30
  • I also see that you improved the code design. – Herman Jaramillo Dec 7 '15 at 21:32

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.