3

I've used scale=0.5 for some of the nodes to make text smaller but a change that code has undergone lately leaves me no choice but to look for a way to keep the node's original size (it is a fixed-width type of node). I don't consider using \tiny, or any of the standard font-size commands, since text looks nothing like scale=0.5 with \tiny (code below is to confirm the difference). What can be done to scale the font of a node without affecting the drawing box of the node?

\documentclass[border=2mm]{standalone}
\usepackage{tikz}
\usetikzlibrary{positioning}
\tikzset
    {%
        ORIGINAL/.style=
            {%
                draw,
                text width=50mm
            }
    }
\begin{document}
    \begin{tikzpicture}
        \path node[ORIGINAL](one)
            { % ORIGINAL TEXT-SIZE (MUST BE CUT IN HALF)
                hello world (original)
            };
        \path node
            [ORIGINAL,scale=0.5,below=2mm of one](two)
            { % BOTH, TEXT AND NODE ARE SCALED-DOWN (NO GOOD)
                hello world (scales node too)
            };
        \path node
            [ORIGINAL,font=\tiny,below=2mm of two   ]
            { % TEXT IS SMALLER BUT NOT ENOUGH AND LOOKS WEIRD (NO GOOD)
                hello world (not exactly right)
            };
    \end{tikzpicture}
\end{document}

4

like this:

enter image description here

for text in second node i use label with scaled content:

\documentclass[border=2mm]{standalone}
\usepackage{tikz}
\usetikzlibrary{positioning}
\tikzset
    {%
        ORIGINAL/.style=
            {%
                draw,
                text width=50mm
            }
    }
\begin{document}
    \begin{tikzpicture}
        \node[ORIGINAL](one)
            { % ORIGINAL TEXT-SIZE (MUST BE CUT IN HALF)
                hello world (original)
            };
        \node[ORIGINAL,below=2mm of one,
             label={[scale=0.5]center:hello world (doesn't scale node size!)}] (two)
            {   };
    \end{tikzpicture}
\end{document}

addendum. new version of above mwe which consider your comments below:

enter image description here

for this image i redefine node style. now has two parameters: text width and scale. their values are for not scaled nodes set by /.default, for other nodes had to be written in used nodes options. this solution require fit tikz library:

\documentclass[tikz, border=2mm]{standalone}
\usetikzlibrary{fit, positioning}

\usepackage{lipsum}
\tikzset{%
     N/.style args = {#1/#2}{% N as node (original)
        text width=#1/#2, scale=#2,
        draw,
        outer sep=1mm,
        path picture={%
        \node[inner sep=1mm, draw,
              fit=(path picture bounding box)] {};
                      }
                        },
     N/.default = 50mm/1,
        }% end of tikzset
\begin{document}
    \begin{tikzpicture}
        \node[N] (one) {hello world (original)};
        \node[N=50mm/0.5,
              below=2mm of one] {\lipsum[11]};
    \end{tikzpicture}
\end{document}
| improve this answer | |
  • you just define style for labels. similarly as for "ORIGINAL". – Zarko Nov 1 '17 at 20:58
  • 1
    i will do asap, temporary i'm busy with other obligation ... – Zarko Nov 1 '17 at 21:17
  • 1
    @bp2017, i'm back :-). see addendum in my answer. i'm convinced that it solve your demands. – Zarko Nov 1 '17 at 23:35
2

Here is another suggestion using \scalebox:

\documentclass[border=2mm]{standalone}
\usepackage{tikz}
\usetikzlibrary{positioning}
\tikzset
    {%
        ORIGINAL/.style=
            {%
                draw,
                text width=50mm
            }
    }
\newcommand*\scalenodetext[2][.5]{%
    \pgfmathsetmacro\revscale{1/.5}%
    \scalebox{#1}{\parbox{\revscale\linewidth}{#2}}%
}
\begin{document}
    \begin{tikzpicture}
        \node[ORIGINAL](one)
            { % ORIGINAL TEXT-SIZE (MUST BE CUT IN HALF)
                hello world (original)
            };
        \node
            [ORIGINAL,below=2mm of one   ](two)
            { %
                \scalenodetext{hello world (scaled)}
            };
    \end{tikzpicture}
\end{document}

enter image description here


Or if the height of the node should not change while the text is scaled:

\documentclass[border=2mm]{standalone}
\usepackage{tikz}
\usetikzlibrary{positioning}
\tikzset
    {%
        ORIGINAL/.style=
            {%
                draw,
                text width=50mm
            }
    }
\newsavebox\nodetext
\newcommand*\scalenodetext[2][.5]{%
    \savebox\nodetext{\parbox{\linewidth}{#2}}%
    \vphantom{\usebox\nodetext}%
    \pgfmathsetmacro\revscale{1/.5}%
    \scalebox{#1}{\parbox{\revscale\linewidth}{#2}}%
}
\begin{document}
    \begin{tikzpicture}
        \node[ORIGINAL](one)
            { % ORIGINAL TEXT-SIZE (MUST BE CUT IN HALF)
                hello world (original)
            };
        \node
            [ORIGINAL,below=2mm of one   ](two)
            { %
                \scalenodetext{hello world (scaled)}
            };
    \end{tikzpicture}
\end{document}

enter image description here

| improve this answer | |

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.