Overfull \vbox (1116.51286pt too high) - graph

I am trying to plot two graphs in one document using latex
first is of sinx and cosx
the otherare its inverse
\documentclass{article}
\usepackage[utf8]{inputenc}
\usepackage{pgfplots}
\title{pgfplots}
\pgfplotsset{compat=1.18}
\begin{document}
\section{Sine and Cosine}
\begin{tikzpicture}
\begin{axis}[clip=false,
xmin=0,
xmax=2.5*pi,
ymin=-1.5,
ymax=1.5,
axis lines=middle,
xtick={0,pi/2,3*pi/2,2*pi},
xticklabels={$0$,$\frac{\pi}{2}$,$\pi$,$\frac{3\pi}{2}$,$2\pi$},
xticklabel style={anchor=south west},
xmajorgrids=true,
grid style=dashed,
]
\addplot[domain=0:2*pi,red,samples=100]{sin(deg(x))}
node[right,pos=0.9]{$f(x)=sin(x)$};
\addplot[domain=0:2*pi,blue,samples=100]{cos(deg(x))}
node[right,pos=0.9]{$g(x)=cos(x)$};
\end{axis}
\end{tikzpicture}
\section{Inverse Sine and Cosine}
\begin{tikzpicture}
\begin{axis}[clip=false,
ymin=-1.5*pi,
ymax=1.5*pi,
xmin=-1.5,
xmax=1.5,
axis lines=middle,
ytick={-pi/2,0,pi/2},
yticklabels={-$\frac{\pi}{2}$,$0$,$\frac{\pi}{2}$},
yticklabel style={anchor=north west},
xmajorgrids=true,
grid style=dashed,
]
\addplot[domain=-1:1,red,samples=100]{asin(x/180*pi)}
node[right,pos=0.9]{$f(x)=sin^{-1}(x)$};
\addplot[domain=-1:1,blue,samples=100]{acos(x/180*pi)}
node[right,pos=0.9]{$g(x)=cos^{-1}(x)$};
\end{axis}
\end{tikzpicture}
\end{document}
here is the code
first i tried with only one section and it worked just fine but when i added another section
it gave the error:
Overfull \vbox (1116.51286pt too high)
I am new to latex so please ignore any rookie mistakes
I have attached the output image it is ploting both graph on different pages is there anyway to plot them on the same page.

Nothing to do with latex, just a math problem: Don't convert the argument of acos to rad, it is the result of the expression which you want to convert.
\documentclass{article}
\usepackage[utf8]{inputenc}
\usepackage{pgfplots}
\title{pgfplots}
\pgfplotsset{compat=1.18}
\begin{document}
\section{Sine and Cosine}
\begin{tikzpicture}
\begin{axis}[clip=false,
xmin=0,
xmax=2.5*pi,
ymin=-1.5,
ymax=1.5,
axis lines=middle,
xtick={0,pi/2,3*pi/2,2*pi},
xticklabels={$0$,$\frac{\pi}{2}$,$\pi$,$\frac{3\pi}{2}$,$2\pi$},
xticklabel style={anchor=south west},
xmajorgrids=true,
grid style=dashed,
]
\addplot[domain=0:2*pi,red,samples=100]{sin(deg(x))}
node[right,pos=0.9]{$f(x)=sin(x)$};
\addplot[domain=0:2*pi,blue,samples=100]{cos(deg(x))}
node[right,pos=0.9]{$g(x)=cos(x)$};
\end{axis}
\end{tikzpicture}
\section{Inverse Sine and Cosine}
\begin{tikzpicture}
\begin{axis}[clip=false,
% ymin=-1.5*pi,
% ymax=1.5*pi,
xmin=-1.5,
xmax=1.5,
axis lines=middle,
ytick={-pi/2,0,pi/2},
yticklabels={-$\frac{\pi}{2}$,$0$,$\frac{\pi}{2}$},
yticklabel style={anchor=north west},
xmajorgrids=true,
grid style=dashed,
]
\addplot[domain=-1:1,red,samples=100]{rad(asin(x))}
node[right,pos=0.9]{$f(x)=sin^{-1}(x)$};
\addplot[domain=-1:1,blue,samples=100]{rad(acos(x))}
node[right,pos=0.9]{$g(x)=cos^{-1}(x)$};
\end{axis}
\end{tikzpicture}
\end{document}

Related

No shape named X is known

I am trying to create a tikz picture with pgfplots featuring an angle with the tkz-euclide package. However, after much difficulty, I am unable to compile the latex document.
I tried changing the paramaters within the path. Nothing seems to be working. Removal of the \tkzMarkAnglesize=0.5cm,mark=|; line will allow the code to work but the angle obviously won't show up.
\begin{figure}[ht]
\begin{center}
\tikzset{every picture/.style={xscale=1,yscale=1}}
\begin{tikzpicture}
\begin{axis}[
domain=0:8,
xmin=0, xmax=8,
ymin=0, ymax=8,
samples=400,
yticklabels={,,},
xticklabels={,,},
ticks=none,
axis y line=center,
axis x line=middle,
xscale=2, yscale=1.5,
clip=false,
]
\addplot+[thick, smooth, mark=none, color=black, width=0.1in] plot coordinates
{(0,3) (8,7)};
\addplot+[thick, smooth, mark=none, color=black, width=0.1in] plot coordinates
{(6,6) (8,6)};
\path
(8,7)node(A){}
(6,6)node(B){}
(8,6)node(C){};
\tkzMarkAngle[size=0.5cm,mark=|](A,B,C);
\node[label={180:{$\theta_H$}},circle,fill,inner sep=0pt] at (axis cs:0,3) {};
\addplot+[thick, smooth, mark=none, color=black, width=0.1in] plot coordinates
{(0,1) (8,3)};
\node[label={180:{$\theta_L$}},circle,fill,inner sep=0pt] at (axis cs:0,1) {};
\end{axis}
\end{tikzpicture}
\end{center}
\end{figure}
Error: No shape named B is known
Here is a minimal working example (upon request):
\documentclass{article}
\usepackage[utf8]{inputenc}
\usepackage{amsmath}
\usepackage{pgfplots}
\pgfplotsset{compat=1.11}
\usepackage{tkz-euclide}
\usepackage{tikz}
\usetkzobj{all}
\begin{document}
\begin{figure}[ht]
\begin{center}
\tikzset{every picture/.style={xscale=1,yscale=1}}
\begin{tikzpicture}
\begin{axis}[
domain=0:8,
xmin=0, xmax=8,
ymin=0, ymax=8,
samples=400,
yticklabels={,,},
xticklabels={,,},
ticks=none,
axis y line=center,
axis x line=middle,
xscale=2, yscale=1.5,
clip=false,
]
\addplot+[thick, smooth, mark=none, color=black, width=0.1in] plot coordinates {(0,3) (8,7)};
\addplot+[thick, smooth, mark=none, color=black, width=0.1in] plot coordinates {(6,6) (8,6)};
\path
(8,7)node(A){}
(6,6)node(B){}
(8,6)node(C){};
\node[label={180:{$\theta_H$}},circle,fill,inner sep=0pt] at (axis cs:0,3) {};
\addplot+[thick, smooth, mark=none, color=black, width=0.1in] plot coordinates {(0,1) (8,3)};
\node[label={180:{$\theta_L$}},circle,fill,inner sep=0pt] at (axis cs:0,1) {};
\end{axis}
\end{tikzpicture}
\end{center}
\end{figure}
\end{document}

Too much white space between caption and figure produced by tikzDevice and ggplot2 in LaTeX

I'm currently using R's ggplot2 and tikzDevice packages to produce graphics and introduce them in LaTeX documents, but I'm struggling with the resulting big white spaces between the figures and the captions, as you can see if you compare the images (I've manually highlighted the spaces to make it clearer):
Here's my MWE:
The R code:
library(ggplot2)
library(tikzDevice)
set.seed(1)
x <- rnorm(200)
tikz(file = "Rplots.tex", width = 4, height = 4)
qplot(x, geom = "histogram")
dev.off()
and the LaTeX code:
\documentclass{article}
\usepackage{tikz}
\begin{document}
\begin{figure}
\centering
\include{Rplots}
\caption{\texttt{ggplot2} plot.}
\end{figure}
\begin{figure}
\centering
\begin{tikzpicture}[scale=3]
\clip (-0.1,-0.2)
rectangle (1.8,1.2);
\draw[step=.25cm,gray,very thin]
(-1.4,-1.4) grid (3.4,3.4);
\draw (-1.5,0) -- (2.5,0);
\draw (0,-1.5) -- (0,1.5);
\draw (0,0) circle (1cm);
\filldraw[fill=green!20!white,
draw=green!50!black]
(0,0) -- (3mm,0mm)
arc (0:30:3mm) -- cycle;
\end{tikzpicture}
\caption{\texttt{tikz} plot.}
\end{figure}
\end{document}
I'd like to know how to get rid of the great space between the caption and the figure via ggplot2.
PS. R version: 3.2.3, ggplot2 version: 2.1.0, tikzDevice version: 0.10-1. I've taken the code for the second plot from Tobias Oetiker's The Not so Short Introduction to LaTeX 2e, version 5.05, page 116.
It's been so long since I asked this question, but I wanted to answer what was the problem in the end.
As you can see in this question on the differences between \input{} and \include{}, the problem has to do with the fact that \include{} does a \clearpage before and after \include{}, that generates the white space I was talking about.
On the other hand, using \input{} is the equivalent to copy and pasting the code into the LaTeX document, that will prevent the white spaces.
it sounds more like a LaTeX question; I think the standard way to tweak the space is to set \abovecaptionskip
\documentclass{article}
\usepackage{tikz}
\setlength{\abovecaptionskip}{-15pt}
\begin{document}
\begin{figure}
\centering
\include{Rplots}
\caption{\texttt{ggplot2} plot.}
\end{figure}
\end{document}
I still don't get your problem, but let me suggest this complete example showing the exact same spacing for the tikz and standard pdf device when used in a knitr document.
---
title: "Untitled"
header-includes:
- \usepackage{caption}
output:
pdf_document:
fig_caption: yes
---
First, we try this
```{r pdf, echo=FALSE, dev='pdf', fig.height=2, fig.width=2, fig.cap='This is a standard graphic.'}
library(ggplot2)
ggplot() + theme(plot.background=element_rect(colour = "red"))
```
Next, we try this
```{r tikz, echo=FALSE, dev='tikz', fig.height=2, fig.width=2, fig.cap='This is a tikz graphic.'}
ggplot() + theme(plot.background=element_rect(colour = "red"))
```
\newpage
## Fixing space
\captionsetup{skip=0pt}
```{r pdf2, echo=FALSE, dev='pdf', fig.height=2, fig.width=2, fig.cap='This is a standard graphic.'}
library(ggplot2)
ggplot() + theme(plot.background=element_rect(colour = "red"))
```
```{r tikz2, echo=FALSE, dev='tikz', fig.height=2, fig.width=2, fig.cap='This is a tikz graphic.'}
ggplot() + theme(plot.background=element_rect(colour = "red"))
```

Line breaks between two plots in knitr

I have a R code block in a knitr document (.Rnw) that calls two functions draw.hist and plot.timeseries, of which each is supposed to create a different plot.
# HEADER
\documentclass{article}
\usepackage[default]{lato}
\usepackage[T1]{fontenc}
\usepackage[sc]{mathpazo}
\usepackage{geometry}
\geometry{verbose,tmargin=2.5cm,bmargin=2.5cm,lmargin=2.5cm,rmargin=2.5cm}
\setcounter{secnumdepth}{1}
\setcounter{tocdepth}{2}
\usepackage{url}
\usepackage[unicode=true,pdfusetitle,
bookmarks=true,bookmarksnumbered=true,bookmarksopen=true,bookmarksopenlevel=1,
breaklinks=false,pdfborder={0 0 1},backref=false,colorlinks=false]
{hyperref}
\hypersetup{
pdfstartview={XYZ null null 1}}
# HERE I START DRAWING
<<test, echo = FALSE, warning = FALSE, fig.width=5, fig.height = 3 >>=
draw.hist(data$c1, "test_name_1")
plot.timeseries(data$c1)
#
I know that I could create two separate R blocks, but this is not an option for me.
How can I add line breaks between the two plots?
(I couldn't find anything suitable in the Chunk options. )
\documentclass{article}
\begin{document}
<<echo = FALSE, fig.height = 3>>=
plot(1)
asis_output("\\\\[2cm]")
plot(2)
#
\end{document}
This adds a line break with 2cm of additional whitespace between the plots. Note that each backslashes is escaped by an additional backslash, therefore \\ becomes \\\\.
Is there an option that you could use an external CSS and increase the margin? Or my quick and dirty solution would be to paste a bunch of <br> tags?

Position of plots using knitr

Consider these two chunks:
\subsection{Section figure 1}
\begin{figure}[!h]
<<figure1>>=
plot(1, 1)
#
\caption{Figure 1}
\end{figure}
\newpage
\subsection{Section figure 2}
<<figure2, fig.cap="figure 2", fig.show='asis'>>=
plot(2, 2)
#
The plot is located after the "Section figure x" title in the first chunk but before in the second one. However, based on documentation, it seems to me that these two chunks should be similar.
So my question: how to show the plot after title section using fig.cap="figure 2".
I try this solution:
\subsection{Essai figure 2 bis}
\begin{figure}[!h]
\end{figure}
<<figure2bis, fig.cap="figure 2 bis", fig.show='asis'>>=
plot(2.5, 2.5)
#
But it generates a page with only the section title before the plot.
Thanks a lot
Marc
You should specify the figure position as a chunk option using the fig.pos tag. In your example you can do the following:
\subsection{Section figure 2}
<<figure2, fig.cap="figure 2", fig.show='asis', fig.pos='!h'>>=
plot(2, 2)
#

Embed R plot in beamer frame using knitr

I am trying to adjust the vertical alignment of a plot in a beamer object. Here is an example:
\documentclass{beamer}
% To change margins for all slides
\setbeamersize{text margin left=0.5cm,text margin right=0.5cm}
\begin{document}
\title{Title of talk}
\author{John Doe}
\maketitle
\begin{frame}[fragile]
\frametitle{Make a plot}
Code:
<<plot_something, fig.width=3.5, fig.height=3.5, fig.align='center'>>=
plot(1:100, rnorm(100), ylab = "Random value")
#
\end{frame}
\end{document}
The position of the plot in the resulting .pdf file is too far down. How do I adjust the position so that the whitespace above the plot is used more efficiently?
I figured it out. The standard margins of a plot object are wide so resetting them does the trick:
\documentclass{beamer}
% To change margins for all slides
\setbeamersize{text margin left=0.5cm,text margin right=0.5cm}
\begin{document}
\title{Title of talk}
\author{John Doe}
\maketitle
\begin{frame}[fragile]
\frametitle{Make a plot}
Code:
<<plot_something, fig.width=3.5, fig.height=2, fig.align='center'>>=
par(mai=c(0.4,0.4,0.2,0.2))
plot(1:100, rnorm(100), ylab = "Random value")
#
\end{frame}
\end{document}

Resources