0

I am using R and the knitr package to produce a LaTeX PDF. As the MWE below demonstrates, an extra, blank page is created before my boxed page, which is to be the cover of a book.

If I remove the final \\ after the Release 1.0 line, the extra page disappears. But this seems a hacky solution. More important, the same change did not fix the problem in my longer document.

I would very much appreciate finding out what I am doing wrong.

EDIT: AT DAVID Carlisle's suggestion, I hope this is the tex:

\documentclass{book}
\usepackage{graphicx}
\usepackage{color}
%% maxwidth is the original width if it is less than linewidth
%% otherwise use linewidth (to make sure the graphics do not exceed the margin)
\makeatletter
\def\maxwidth{ %
  \ifdim\Gin@nat@width>\linewidth
    \linewidth
  \else
    \Gin@nat@width
  \fi
}
\makeatother
\definecolor{fgcolor}{rgb}{0.345, 0.345, 0.345}
\newcommand{\hlnum}[1]{\textcolor[rgb]{0.686,0.059,0.569}{#1}}%
\newcommand{\hlstr}[1]{\textcolor[rgb]{0.192,0.494,0.8}{#1}}%
\newcommand{\hlcom}[1]{\textcolor[rgb]{0.678,0.584,0.686}{\textit{#1}}}%
\newcommand{\hlopt}[1]{\textcolor[rgb]{0,0,0}{#1}}%
\newcommand{\hlstd}[1]{\textcolor[rgb]{0.345,0.345,0.345}{#1}}%
\newcommand{\hlkwa}[1]{\textcolor[rgb]{0.161,0.373,0.58}{\textbf{#1}}}%
\newcommand{\hlkwb}[1]{\textcolor[rgb]{0.69,0.353,0.396}{#1}}%
\newcommand{\hlkwc}[1]{\textcolor[rgb]{0.333,0.667,0.333}{#1}}%
\newcommand{\hlkwd}[1]{\textcolor[rgb]{0.737,0.353,0.396}{\textbf{#1}}}%
\let\hlipl\hlkwb
\usepackage{framed}
\makeatletter
\newenvironment{kframe}{%
 \def\at@end@of@kframe{}%
 \ifinner\ifhmode%
  \def\at@end@of@kframe{\end{minipage}}%
  \begin{minipage}{\columnwidth}%
 \fi\fi%
 \def\FrameCommand##1{\hskip\@totalleftmargin \hskip-\fboxsep
 \colorbox{shadecolor}{##1}\hskip-\fboxsep
     % There is no \\@totalrightmargin, so:
     \hskip-\linewidth \hskip-\@totalleftmargin \hskip\columnwidth}%
 \MakeFramed {\advance\hsize-\width
   \@totalleftmargin\z@ \linewidth\hsize
   \@setminipage}}%
 {\par\unskip\endMakeFramed%
 \at@end@of@kframe}
\makeatother
\definecolor{shadecolor}{rgb}{.97, .97, .97}
\definecolor{messagecolor}{rgb}{0, 0, 0}
\definecolor{warningcolor}{rgb}{1, 0, 1}
\definecolor{errorcolor}{rgb}{1, 0, 0}
\newenvironment{knitrout}{}{} % an empty environment to be redefined in TeX
\usepackage{alltt}   
\usepackage[margin = 0.8in]{geometry}
\usepackage{afterpage}  % if coloring only one page, like the cover, use this at end
% https://tex.stackexchange.com/questions/25137/how-to-change-the-background-color-only-for-the-current-page
\usepackage{pagecolor}
\usepackage{xcolor}
\definecolor{lm_green}{RGB}{120, 162, 47}
%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%
\IfFileExists{upquote.sty}{\usepackage{upquote}}{}
\begin{document}
\newpagecolor{blue}
\thispagestyle{empty}    % removes header and page number on this page; like Excel Diff page number

\colorbox{lm_green}{                            
    \parbox[c]{0.98\linewidth}{
        \fontsize{65pt}{80pt}\selectfont             
        \vspace*{2in}                          
        \textcolor{white}{Data Graphs for Legal Management} \hspace{.3in} \\           
        \textcolor{white}{A competitive advantage for decisions} \hspace{.3in} \\
    \vspace*{1in}                                
    \textcolor{white}{\LARGE Rees W. Morrison, Esq.} \hspace{.3in} \\  %\large does not take an argument, re Carlisle
   %\vspace*{.1in}  
   \textcolor{white}{\LARGE Release 1.0} \\ 
   %\hfill \\
\par    
    }
}

\vspace*{2in}

\clearpage

\restorepagecolor

\end{document}

2.

\documentclass{book}   
\usepackage[margin = 0.8in]{geometry}
\usepackage{afterpage}  % if coloring only one page, like the cover, use this at end
% https://tex.stackexchange.com/questions/25137/how-to-change-the-background-color-only-for-the-current-page
\usepackage{pagecolor}
\usepackage{xcolor}
\definecolor{lm_green}{RGB}{120, 162, 47}
%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%
\begin{document}
\newpagecolor{blue}
\thispagestyle{empty}    % removes header and page number on this page; like Excel Diff page number
\colorbox{lm_green}{                            
    \parbox[c]{0.98\linewidth}{
        \fontsize{65pt}{80pt}\selectfont             
        \vspace*{2in}                          
        \textcolor{white}{Data Graphs} \hspace{.3in} \\           
        \textcolor{white}{A competitive advantage for decisions} \hspace{.3in} \\
    \vspace*{1in}                                
    \textcolor{white}{\LARGE{Confused by LaTeX}} \hspace{.3in} \\
   %\vspace*{.1in}  
   \textcolor{white}{\LARGE{Release 1.0}} \\ 
   %\hfill \\
\par    
    }
}

\vspace*{2in}

\clearpage

\restorepagecolor

<<setup, echo = FALSE, message = FALSE, cache = FALSE>>=
source("C:/Users/Rees/Documents/R/Scripts/gcm.R") 
opts_chunk$set(echo=F, warning=F, message=F, cache=T, fig.align='center', comment=NA)
@

\end{document}
Bobyandbob
  • 4,899
lawyeR
  • 169
  • can you show the generated latex rather than the R input? more people would be able to test it then. I'd be cautions about using afterpage and note that size commands do not take an argument so the syntax should be \LARGE Release 1.0 not \LARGE{Release 1.0} never use \\ at the end of a paragraph (it presumably makes underfull hbox warnings?) – David Carlisle May 16 '17 at 14:43
  • why do you say removing the \\ is hacky? the \\ in that position is certainly wrong. – David Carlisle May 16 '17 at 14:45
  • @DavidCarlisle, how do I "show the generated latex"? My directory has an .ilg, an .ind and the Text document. As to cautions, are you suggesting I omit the afterpage library? Much obliged for the guidance on LARGE and \ at the end. – lawyeR May 16 '17 at 15:15
  • I don't have R/knitr so I don't know how exactly the pipeline works but basically <<setup, ech... is not tex, it's instructions to R to generate some tex which must then be passed to latex. I was assuming that there was a mode in which you could see the tex file. Or in other words, just replace << chunk by any text that you can check shows the issue, then we can run the example just using latex, not requiring R – David Carlisle May 16 '17 at 15:18
  • @DavidCarlisle Does the edit provide what you need? i have not fixed your two points. – lawyeR May 16 '17 at 15:37
  • You've got two documents there? – cfr May 16 '17 at 23:21
  • @cfr I realize now that it does seem to have two. It's what was in the file. Are you able to use the second one to reproduce my problem and give some advice? – lawyeR May 17 '17 at 14:22

0 Answers0