2

I need to have a pie char near a descption block like:

-----------------------------------
| Righe totali      |             |
| Completezza       |  pie chart  |
|                   |             |
-----------------------------------

at this moment my code is:

\documentclass[a4paper,12pt,oneside]{report}

\usepackage{pgf-pie} %grafici pie
\usepackage{tikz} %grafici pie
\pgfkeys{/number in legend/.code=
    \expandafter\let\expandafter\ifpienumberinlegend
    \csname if#1\endcsname
    \ifpienumberinlegend
    \let\legendbeforenumber\beforenumber
    \let\legendafternumber\afternumber
    \def\beforenumber##1\afternumber{}%
    \fi,
    /number in legend/.default=true
}


\begin{document}

\begin{description}
    \item[Righe totali] 1,699,382
    \item[Copletezza] 0.76698 (valore inventato) 
    \begin{tikzpicture}
        \pie[color={black!10}, text=legend, sum=1, radius=0.5, number in legend]{0.76698/ Completezza}
    \end{tikzpicture}
\end{description}
\end{document}

But I know it isn't correct. How can I do it?

Torbjørn T.
  • 206,688
Razzo
  • 65
  • 4
    welcome to TeX-SE!please, extend your code snipped to complete but small document with \documentclas{...} on beginning and \end{document} on the end. – Zarko Jun 17 '17 at 12:04
  • 1
    How should the picture be positioned? – samcarter_is_at_topanswers.xyz Jun 17 '17 at 12:10
  • Reference for number in legend: https://tex.stackexchange.com/questions/112140/put-numbers-in-legend-using-pgf-pie – Torbjørn T. Jun 17 '17 at 12:49
  • If what you're asking is how to move the diagram up/down in relation to the line of text it's placed on, you want the baseline key, e.g. \begin{tikzpicture}[baseline=2mm] – Torbjørn T. Jun 17 '17 at 12:52
  • 2
    Where is \pie defined? It's not in standard tikz. – JPi Jun 17 '17 at 12:55
  • 2
    Put the description in a minipage and the picture in another. \begin{minipage}{.5\linewidth}\begin{description}...\end{description}\end{minipage}\begin{minipage{.45\linewidth}\begin{tikzpicture}...\end{tikzpicture}\end{minipage}. Adjust widths as desired. – cfr Jun 17 '17 at 12:58
  • 1
    Looks like @cfr's comment is what you're after. – Torbjørn T. Jun 17 '17 at 14:50
  • thanks! I solve using:

    \begin{minipage}[c]{.5\textwidth} \begin{description} \item[Righe totali] 1,699,382 \item[Copletezza] 0.76698 (valore inventato) \end{description} \end{minipage} \begin{minipage}[c]{.5\textwidth} \begin{tikzpicture} \pie[color={black!10}, text=legend, sum=1, radius=0.5, number in legend]{0.76698/ Completezza} \end{tikzpicture} \end{minipage}

    – Razzo Jun 17 '17 at 14:51
  • @cfr would you like to convert your comment into an answer? – samcarter_is_at_topanswers.xyz Jun 17 '17 at 15:13
  • @samcarter Done ;). – cfr Jun 17 '17 at 22:06
  • 1
    @Razzo Note that if you use .5\textwidth for both, you should make sure that any line ending between the two is commented as there is not room for a space there. Also, make sure that you use \noindent if there's a paragraph break before them. Otherwise, you'll get bad box warnings. (This is why I used only .5 and .45 of the available width, as the picture really didn't need half of the line. – cfr Jun 17 '17 at 22:09

3 Answers3

3

I guess you are using pgf-pie.sty. You can put the number in the label your self by removing it from the chart and typing it directly in the label. To remove the number from the chart use a \gobble command (don't print argument) in before number. In the following example I have defined a command for it so you don't have to type the number twice. (This command only works if you have one input number. Otherwise you need to add the number by hand).

\documentclass{article}
\usepackage{tikz,pgf-pie}
\usepackage{lipsum}
\newcommand\gobble[1]{}
\newcommand\MyPie[2]{% Number, label
  \smash{%
    \begin{tikzpicture}
      \pie[color={black!10}, text=legend, sum=1, radius=0.5,before number=\gobble,after number=,]{#1/ #2 #1}
    \end{tikzpicture}}}
\begin{document}
\lipsum[1]

\begin{description}
\item[Righe totali] 1,699,382
\item[Copletezza] 0.76698 (valore inventato) \MyPie{0.76698}{Copletezza}
\end{description}  

\lipsum[2]
\end{document}

enter image description here

StefanH
  • 13,823
3

I think you want to align the list with the picture, keeping normal line-spacing within the list itself.

This can be done by putting the list in one miniopage and the picture in another. For example,

\documentclass[a4paper,12pt]{report}
\usepackage{geometry}% for correct A4
\usepackage{pgf-pie,calc} %grafici pie
\pgfkeys{/number in legend/.code=
  \expandafter\let\expandafter\ifpienumberinlegend
  \csname if#1\endcsname
  \ifpienumberinlegend
  \let\legendbeforenumber\beforenumber
  \let\legendafternumber\afternumber
  \def\beforenumber##1\afternumber{}%
  \fi,
  /number in legend/.default=true
}
\begin{document}
\begin{minipage}{.5\linewidth}
  \begin{description}
    \item[Righe totali] 1,699,382
    \item[Copletezza] 0.76698 (valore inventato)
  \end{description}
\end{minipage}
\begin{minipage}{.45\linewidth}
  \begin{tikzpicture}
    \pie[color={black!10}, text=legend, sum=1, radius=0.5, number in legend]{0.76698/ Completezza}
  \end{tikzpicture}
\end{minipage}
\end{document}

pie to right of list

I've used a total of 95% of the text block's width for the mini-pages, with a space between the two. Adjust as desired.

cfr
  • 198,882
1

Something like this?

\documentclass[a4paper,12pt,oneside]{report}


\usepackage{pgf-pie} %grafici pie
\usepackage{tikz} %grafici pie
\pgfkeys{/number in legend/.code=
    \expandafter\let\expandafter\ifpienumberinlegend
    \csname if#1\endcsname
    \ifpienumberinlegend
    \let\legendbeforenumber\beforenumber
    \let\legendafternumber\afternumber
    \def\beforenumber##1\afternumber{}%
    \fi,
    /number in legend/.default=true
}
 \usepackage{lipsum}

\begin{document}

\lipsum[10]
\begin{description}
    \item[Righe totali] 1,699,382
    \item[Copletezza] 0.76698 (valore inventato)\hfill
    \raisebox{0pt}[0pt][0pt]{\begin{tikzpicture}
        \pie[color={black!10}, text=legend, sum=1, radius=0.5, number in legend]{0.76698/ Completezza}
    \end{tikzpicture}}
\end{description}

\lipsum[11]

\end{document} 

enter image description here

Bernard
  • 271,350