4

I have some problems concerning the command \centering. I want to put a tikzpicture in the center of the page but I can't do it. I tried with \centering and with \begin{center}...\end{center} but nothing happened. I have also a problem with axis: I want to resize them but I don't know how to do it. Thank you in advance. The code is:

\documentclass{article}  
\usepackage{pgfplots}  
\begin{document}  
\begin{center}  
\begin{tikzpicture}  
\begin{axis}  
[scale=2.5,axis lines=middle,  
enlargelimits,  
xtick={0,1.57,3.14,6.28},ytick={0.5,1},  
xticklabels={0,$\displaystyle \frac{\pi}{2}$,$\pi$, $2\pi$},  
yticklabels={$1/2$, $1$},  
xlabel=$x$,ylabel=$y$,axis equal]  
\addplot  
[domain=-2*pi:2*pi,samples=100,thick,blue]  
{(sin(deg(x)))^2+cos(deg(x))};  
\end{axis}  
\end{tikzpicture}  
\end{center}  
\end{document}  
2
  • Welcome to TeX.SX! Your scaling is too large and besides that, the margins left and right are not the same by default.
    – user31729
    Feb 28, 2016 at 15:36
  • You should know that \begin{center}...\end{center} adds some vertical space which might not be wanted. (Off-topic for the real issue). Please don't ask more than one question per post.
    – user31729
    Feb 28, 2016 at 15:42

1 Answer 1

3

Using showframe shows the issue -- the margins are not same on the left and right side. Using geometry this can be repaired, the given values are just guesses.

I did not address the axis scaling 'sub'question

\documentclass{article}  
\usepackage[lmargin=1.5cm,rmargin=1.5cm]{geometry}
\usepackage{pgfplots}  
\pgfplotsset{compat=1.13}
\usepackage{showframe} % just for showing the margins
\begin{document}  
\begin{center}  
\begin{tikzpicture}  
\begin{axis}  
[scale=2.5,axis lines=middle,  
enlargelimits,  
xtick={0,1.57,3.14,6.28},ytick={0.5,1},  
xticklabels={0,$\displaystyle \frac{\pi}{2}$,$\pi$, $2\pi$},  
yticklabels={$1/2$, $1$},  
xlabel=$x$,ylabel=$y$,axis equal]  
\addplot  
[domain=-2*pi:2*pi,samples=100,thick,blue]  
{(sin(deg(x)))^2+cos(deg(x))};  
\end{axis}  
\end{tikzpicture}  
\end{center}  
\end{document}  

enter image description here

You must log in to answer this question.

Not the answer you're looking for? Browse other questions tagged .