tikz 缩放一切:路径和文本

tikz 缩放一切:路径和文本

我觉得这应该非常简单,但我不知道该怎么做。

我想要完整缩放 tikz 图形、路径和文本。

我尝试了这两种方法,但都没有导致字体缩放。

\begin{tikzpicture}[scale=0.5]   
\begin{tikzpicture}[scale=0.5,transform shape]

在我的用例中,重要的是所有比例都应保持在任何比例下,小比例下的可读性并不重要,所以我明白这不是通常的需求情况。我需要能够以视觉方式缩小或放大图形而不会以任何方式扭曲它。

以下是一个示例不是光学缩小的图像。

\documentclass[fontsize=12pt]{article}

\RequirePackage{graphicx}

\RequirePackage{tikz}                   %used for diagrams
    \usetikzlibrary{math,arrows,automata,positioning,calc,decorations.footprints,decorations.fractals,decorations.markings,decorations.pathmorphing,decorations.pathreplacing,decorations.shapes,decorations.text}
\begin{document}


\begin{tikzpicture}[scale=1,transform shape]
    \draw [
        postaction={decorate},
        decoration={
            transform={scale=1},
            raise=1.5ex,
            text effects along path,
            text align=center,
            reverse path,
            text={Blue is a pretty color},
            text effects/.cd,
                characters={text along path,scale=1}
        },
        rotate=-90
    ] (0,0) circle (2);
\end{tikzpicture}

\begin{tikzpicture}[scale=0.5,transform shape]
    \draw [
        postaction={decorate},
        decoration={
            transform={scale=1},
            raise=1.5ex,
            text effects along path,
            text align=center,
            reverse path,
            text={Blue is a pretty color},
            text effects/.cd,
                characters={text along path,scale=1}
        },
        rotate=-90
    ] (0,0) circle (2);
\end{tikzpicture}
\end{document}

在此处输入图片描述

答案1

您可以通过计算变换矩阵的雅可比矩阵来确定比例因子。这已在各种早期答案中使用,例如这个这个这个这个。为了避免字距调整不当,您需要添加text effects={text along path}、删除transform={scale=1},键并缩放raise

\documentclass[fontsize=12pt]{article}

% \RequirePackage{graphicx} <- gets loaded by TikZ

\RequirePackage{tikz}                   %used for diagrams
%    \usetikzlibrary{math,arrows,automata,positioning,calc,decorations.footprints,decorations.fractals,decorations.markings,decorations.pathmorphing,decorations.pathreplacing,decorations.shapes,decorations.text}
\usetikzlibrary{decorations.text} %<- for this example we need only this libary
\begin{document}
\tikzset{get scale/.code={\pgfgettransformentries{\tmpa}{\tmpb}{\tmpc}{\tmpd}{\tmp}{\tmp}%
\pgfmathsetmacro{#1}{sqrt(abs(\tmpa*\tmpd-\tmpb*\tmpc))}%
}}

\begin{tikzpicture}[scale=1,transform shape]
    \draw [
        postaction={decorate},
        decoration={
            /tikz/get scale=\myscale,
            raise=\myscale*1.5ex,
            text effects along path,
            text align=center,
            reverse path,
            text={Blue is a pretty color},
            text effects/.cd,
                characters={text along path,scale=\myscale}
        },text effects={text along path},
        rotate=-90
    ] (0,0) circle (2);
\end{tikzpicture}

\begin{tikzpicture}[scale=0.5,transform shape]
    \draw [
        postaction={decorate},
        decoration={
            /tikz/get scale=\myscale,
            raise=\myscale*1.5ex,
            text effects along path,
            text align=center,
            reverse path,
            text={Blue is a pretty color},
            text effects/.cd,
                characters={text along path,scale=\myscale}
        },text effects={text along path},
        rotate=-90
    ] (0,0) circle (2);
\end{tikzpicture}
\end{document}

在此处输入图片描述

答案2

到目前为止我看到的最好的答案可以在这里找到正确缩放 tikzpicture

它指定使用\resizebox{h}{v}{target}\scalebox{s}{target}。要按比例缩放,请使用!

相关内容