对齐 tikzpicture

对齐 tikzpicture

我,

我想让这两个 tikzpicture 并排显示。无需更改代码,可以吗?

\documentclass{article}
\usepackage{subfig}
\usepackage{amsmath}
\usepackage{tikz}


\usepackage{pgf-pie}
\usepackage{pgfplots}
\usepackage{bchart}

\usepackage{graphicx}

\usepackage{tikz,stackengine}
\def\stackalignment{r}
\setstackgap{S}{2pt}




\def\stackalignment{r}
\newcommand\pielabelon[3][0pt]{%
\abovebaseline[#3]{#2%
    \makebox[-\dimexpr8pt+#1]{\smash{%
            \stackunder{}{\rule{1pt}{\dimexpr#3+2.5ex}}}}}
}
\newcommand\pielabelunder[3][0pt]{%
\belowbaseline[#3]{#2%
    \makebox[-\dimexpr8pt+#1]{\smash{%
            \stackon{\rule{0pt}{1.3ex}}{\rule{1pt}      {\dimexpr#3+2.5ex}}}}}
}

\newcommand{\slice}[4]{
\pgfmathparse{0.5*#1+0.5*#2}
\let\midangle\pgfmathresult

% slice
\draw[thick,fill=black!10] (0,0) -- (#1:1) arc (#1:#2:1) -- cycle;

% outer label
\node[label=\midangle:#4] at (\midangle:1) {};

% inner label
\pgfmathparse{min((#2-#1-10)/110*(-0.3),0)}
\let\temp\pgfmathresult
\pgfmathparse{max(\temp,-0.5) + 0.8}
\let\innerpos\pgfmathresult
\node at (\midangle:\innerpos) {#3};
  }

  \newcounter{a}
  \newcounter{b}

  \begin{document}


  \begin{figure}
  \centering
  \subfloat[In-only]{\label{fig:in}
  \begin{tikzpicture}

  \newcounter{i}
  \newcounter{j}
  \foreach \p/\t in {
45/Absolute Return Bonds, 
45/Emerging Market Debt,
7/Equity (7\%),
3/Property (3\%)}
   {
\setcounter{a}{\value{b}}
\addtocounter{b}{\p}
\slice{\thea/100*360}
{\theb/100*360}
{\ifnum\p>10\relax\p\%\fi}{\t}
   }

  \end{tikzpicture}
  }
   \quad
      \subfloat[In-only]{\label{fig:in}
    \begin{tikzpicture}

   \newcounter{e}
  \newcounter{h}
   \foreach \p/\t in {
45/Absolute Return Bonds, 
45/Emerging Market Debt,
7/Equity (7\%),
3/Property (3\%)}
     {
\setcounter{a}{\value{b}}
\addtocounter{b}{\p}
\slice{\thea/100*360}
{\theb/100*360}
{\ifnum\p>10\relax\p\%\fi}{\t}
    }

   \end{tikzpicture}
    }

\end{figure}
    \end{document}

我尝试使用 subfloat 来实现,但是没有效果。

答案1

嗯,这取决于你的意思无需更改代码;你必须改变某物。问题是这些图形占用了太多的水平空间,无法并排放置(前提是您不想扩展文本宽度)。美学问题是两个长标签的自动放置。我建议Absolute Return Bonds

\makebox[1.3cm][r]{Absolute Return Bonds}

以及Emerging Market Debt

\makebox[1.3cm][l]{Emerging Market Debt}

得到下图。你可以通过调整 的长度来修改标签的位置1.3cm

在此处输入图片描述

相关内容