I'm trying to draw a graph with the associated table of data using pgfplots. It works great, but the graph itself isn't aligned with the table. This is what it looks like:
I don't like the overhang. How can I move the position of the graph?
I would like to either line up one side or another. This is what it would look like if I could line them up to the right:
I could deal with only being able to do that, but it would also be useful to have a more general way to move the graph.
I've looked around in the pgfplots manual, as well as the pgf manual, but I couldn't find anything that looked promising. I'm fairly new to LaTeX, only been using it for a few days, so feel free to just point me in the right direction.
Code:
Results:\\
\begin{tabular}{| c | c | c |}
\hline
\textbf{QP} & \textbf{Average PSNR\_Y ($dB$)} & \textbf{Total bits} \\
\hline
1 & 49.197166 & 14593504\\
\hline
8 & 32.003399 & 1106824\\
\hline
16 & 28.387211 & 374880\\
\hline
24 & 26.661640 & 206704\\
\hline
31 & 25.740038 & 150056\\
\hline
\end{tabular}
\vspace*{2em}
\noindent
\begin{tikzpicture}
\begin{axis}[
xlabel=$QP$,
ylabel={$Encoding Quality$}
]
% use TeX as calculator:
% \addplot {x^2 - x +4};
\addplot coordinates {
(1,49.197166)
(8,32.003399)
(16,28.387211)
(24,26.661640)
(31,25.740038)
};
\addlegendentry{ PSNR\_Y }
\addplot coordinates {
(1,58.374016)
(8,4.427296)
(16,1.49952)
(24,0.826816)
(31,0.600224)
};
\addlegendentry{Total Bits $\times250,000$}
\end{axis}
\end{tikzpicture}
Best Answer
I think the
trim right
andtrim left
options are only useful if there is something which sticks out of the axis' box -- for example, if you want to exclude a legend from the horizontal alignment.In your case, it appears to me that it suffices to surround the table and the graphics with
If you have multiple elements which you want to align, you can also pack all of them into a tabular (which supports left-aligned or right-aligned columns in a natural way).
Once you start with horizontal and vertical alignment, you should consider using the
\begin{tikzpicture}[baseline]
option and the\begin{tabular}[c]
flag as well -- both are part of the associated control mechanisms (which are explained in more detail in the pgfplots manual, there is a section "Alignment" somewhere which should also cover these specific cases).