饼图与小页面不一致

饼图与小页面不一致

我的目标是以相同的比例并排显示两个饼图并对齐它们。这似乎对我来说不起作用,我不确定问题可能是什么。可能是命令\resizebox{}{}导致了问题?

抱歉代码有点乱。提前感谢大家的帮助。

\begin{figure}[ht]
\begin{minipage}[b]{0.45\textwidth}
    \centering
    \resizebox{7cm}{!}{
        \begin{tikzpicture}
            \def\printonlylargeenough#1#2{\unless\ifdim#2pt<#1pt\relax
                #2\printnumbertrue
                \else
                \printnumberfalse
                \fi}
            \newif\ifprintnumber
            \pie[
            /tikz/every pin/.style={align=center},
            radius=3,before number=\printonlylargeenough{3},
            after number=\ifprintnumber\%\fi,
            text=legend,
            explode = {0.3,0,0,0},
            color={p1!50, p2!50, p3!50, p4!50}]
            {
                88.5/Fahrer,
                2.9/Fußgänger,
                7.5/Wetter,
                1.1/Technik
            }
        \end{tikzpicture}
    }
\end{minipage}\hfill
\begin{minipage}[b]{0.45\textwidth}
    \centering
    \resizebox{7cm}{!}{
        \begin{tikzpicture}
            \def\printonlylargeenough#1#2{\unless\ifdim#2pt<#1pt\relax
                #2\printnumbertrue
                \else
                \printnumberfalse
                \fi}
            \newif\ifprintnumber
            \pie[
            /tikz/every pin/.style={align=center},
            radius=3 , before number=\printonlylargeenough{3.5},
            after number=\ifprintnumber\%\fi,
            text=legend,
            color={p1!40, p2!40, p3!40, p4!40, p5!40, p6!40}]
            {
                20/Abbiegevorgänge,
                18/Vorfahrt,
                14.7/Abstand,
                10.9/Geschwindigkeit,
                3.2/Alkohol,
                33.2/Andere Gründe
            }
        \end{tikzpicture}
    }
\end{minipage}\hfill
\caption{Ursache für Unfälle mit Personenschaden (a) sowie das Fehlverhalten des Fahrers (b) im Jahr 2020 nach \autocite{sta2021}}
\label{fig:abb1}
\end{figure}

在此处输入图片描述

答案1

为了正确打印,我更resize喜欢使用scale保持文本、线条粗细等不变。

唯一的手动调整是将第一张图片垂直位移 - 5pt

d

\documentclass[12pt]{article}

\usepackage[ngerman]{babel}
\usepackage{graphicx}
\usepackage[left=2.00cm, right=2.00cm, top=2.00cm, bottom=2.00cm]{geometry}

\usepackage{tikz}
\usepackage{pgf-pie} 

%\usepackage{showframe}% margins

\begin{document}
    \begin{figure}[ht]
        \begin{minipage}[c][5cm][c]{0.45\textwidth} %changed <<<<<<
            \vspace*{-5pt}% added <<<<<<<
                \begin{tikzpicture}[scale=0.75]%changed <<<<<<
                    \footnotesize% added <<<<<<<
                    \def\printonlylargeenough#1#2{\unless\ifdim#2pt<#1pt\relax
                        #2\printnumbertrue
                        \else
                        \printnumberfalse
                        \fi}
                    \newif\ifprintnumber
                    \pie[
                    /tikz/every pin/.style={align=center},
                    radius=3,before number=\printonlylargeenough{3},
                    after number=\ifprintnumber\%\fi,
                    text=legend,
                    explode = {0.3,0,0,0},
                    color={red!50, green!50, blue!50, black!50}]
                    {
                        88.5/Fahrer,
                        2.9/Fußgänger,
                        7.5/Wetter,
                        1.1/Technik
                    }
                \end{tikzpicture}
        \end{minipage}\hfill
        \begin{minipage}[c][5cm][c]{0.5\textwidth}%changed <<<<<<
                \begin{tikzpicture}[scale=0.75]%changed <<<<<<
                    \footnotesize% added <<<<<<<
                    \def\printonlylargeenough#1#2{\unless\ifdim#2pt<#1pt\relax
                        #2\printnumbertrue
                        \else
                        \printnumberfalse
                        \fi}
                    \newif\ifprintnumber
                    \pie[
                    /tikz/every pin/.style={align=center},
                    radius=3 , before number=\printonlylargeenough{3.5},
                    after number=\ifprintnumber\%\fi,
                    text=legend,
                    color={red!40, green!40, black!40, blue!40, yellow!40, violet!40}]
                    {
                        20/Abbiegevorgänge,
                        18/Vorfahrt,
                        14.7/Abstand,
                        10.9/Geschwindigkeit,
                        3.2/Alkohol,
                        33.2/Andere Gründe
                    }
                \end{tikzpicture}
        \end{minipage}
        \caption{Ursache für Unfälle mit Personenschaden (a) sowie das Fehlverhalten des Fahrers \\ (b) im Jahr 2020 nach}
        \label{fig:abb1}
    \end{figure}

\end{document}

答案2

此版本使用[baseline={(0,0)}]选项来居中对齐。由于 中有逗号,因此需要额外的括号(0,0)

\documentclass[12pt]{article}

\usepackage[ngerman]{babel}
\usepackage{graphicx}
\usepackage[left=2.00cm, right=2.00cm, top=2.00cm, bottom=2.00cm]{geometry}

\usepackage{tikz}
\usepackage{pgf-pie} 

%\usepackage{showframe}% margins

\begin{document}
    \begin{figure}[ht]
                \begin{tikzpicture}[scale=0.75, baseline={(0,0)}]%changed <<<<<<
                    \footnotesize% added <<<<<<<
                    \def\printonlylargeenough#1#2{\unless\ifdim#2pt<#1pt\relax
                        #2\printnumbertrue
                        \else
                        \printnumberfalse
                        \fi}
                    \newif\ifprintnumber
                    \pie[
                    /tikz/every pin/.style={align=center},
                    radius=3,before number=\printonlylargeenough{3},
                    after number=\ifprintnumber\%\fi,
                    text=legend,
                    explode = {0.3,0,0,0},
                    color={red!50, green!50, blue!50, black!50}]
                    {
                        88.5/Fahrer,
                        2.9/Fußgänger,
                        7.5/Wetter,
                        1.1/Technik
                    }
                \end{tikzpicture}\hfill
                \begin{tikzpicture}[scale=0.75, baseline={(0,0)}]%changed <<<<<<
                    \coordinate (origin) at (0,0);
                    \footnotesize% added <<<<<<<
                    \def\printonlylargeenough#1#2{\unless\ifdim#2pt<#1pt\relax
                        #2\printnumbertrue
                        \else
                        \printnumberfalse
                        \fi}
                    \newif\ifprintnumber
                    \pie[
                    /tikz/every pin/.style={align=center},
                    radius=3 , before number=\printonlylargeenough{3.5},
                    after number=\ifprintnumber\%\fi,
                    text=legend,
                    color={red!40, green!40, black!40, blue!40, yellow!40, violet!40}]
                    {
                        20/Abbiegevorgänge,
                        18/Vorfahrt,
                        14.7/Abstand,
                        10.9/Geschwindigkeit,
                        3.2/Alkohol,
                        33.2/Andere Gründe
                    }
                \end{tikzpicture}
        \llap{\rule{\textwidth}{0.5pt}}% show baseline, remove from final version
        \caption{Ursache für Unfälle mit Personenschaden (a) sowie das Fehlverhalten des Fahrers \\ (b) im Jahr 2020 nach}
        \label{fig:abb1}
    \end{figure}

\end{document}

演示

相关内容