Treating a quote block similarly to a figure in LaTeX? - latex

Been trying to figure out how to achieve this but can only find ways to do it within the figure environment using wrapfig. I'm using the epigraph package to generate the quote style (as in the screenshot). The current behavior is in this screenshot and generated by the code
\subsection{Methods}
\lipsum[1-2]
\epigraph{Models, of course, are never true, but fortunately it is only necessary that they be useful.}{\textcite{Box1979-em}}
However, the below image is how I wish it to look, but unsure how to achieve this?

Without a MWE, I had to make some adjustments; but this appears to work.
\documentclass[11pt,letterpaper]{article}
\usepackage{lipsum}
\usepackage{epigraph}
\usepackage{biblatex}
\usepackage{wrapfig}
\begin{document}
\setcounter{section}{2}
\subsection{Methods}
\begin{wrapfigure}{r}{0pt}%
\begin{minipage}{0.43\linewidth} % manual adjustment required
\epigraph{Models, of course, are never true, but fortunately it is only necessary that they be useful.}{Box (1979)}
\end{minipage}
\end{wrapfigure}
\lipsum[1-2]
\end{document}

Related

LaTeX change name of \bibliography{} heading (or remove entirely)

I have seen this question asked a few times on here but none of the answers have gotten me exactly what I want. I am using Overleaf to write a LaTeX document and when I make a bibliography (using the natbib library) it automatically makes a heading named "References". Can I remove this heading somehow? I've tried a couple other options but they haven't worked. I've attached a minimal working example below:
\documentclass{article}
\usepackage[utf8]{inputenc}
\usepackage{natbib}
\usepackage{hyperref}
\begin{document}
Here is a citation \citep{Source}.
\bibliographystyle{apalike}
\bibliography{refs}
\end{document}
Not sure what didn't work with the existing responses - perhaps you could point to them and indicate what you didn't like about the results? Does replacing the \bibliography{refs} with the following help? (BTW, as this is not an Overleaf question, it's just LaTeX, perhaps remove the overleaf tag and reference.)
\begingroup
\renewcommand
\refname{}
\bibliography{refs}
\endgroup

Key-value lookup system in Latex macros fails if value has latex tokens

I am trying to use a sort of key-value lookup system in a LaTeX document, but I am having problems when the value itself has LaTeX code within it. In my document, I have the following macro definitions:
\makeatletter
\def\NewLabel#1#2{\expandafter\xdef\csname LBL##1\endcsname{#2}}
\def\Ref#1{\#ifundefined{LBL##1}{???}{\csname LBL##1\endcsname}}
With these macros, I can do the following in my document:
\NewLabel{name1}{John Smith}
\begin{document}
\Ref{name1}
\end{document}
However, the following fails complaining about an extra }:
\usepackage{hyperref}
\NewLabel{name1}{\href{mailto:johnsmith#exmaple.com}{John Smith}}
\begin{document}
\Ref{name1}
\end{document}
I know the solution has to have something to do with \protect or \relax or something like that, but I can't figure out what it is.
Does anyone know the solution to this problem?
I found two solutions to my problem, one using \noexpand and the other changing \xdef to \gdef, though I must admit that I do not fully understand the consequences of my solutions (particularly the use of \gdef). The more narrow solution using \noexpand is:
\documentclass{article}
\makeatletter
\def\NewLabel#1#2{\expandafter\xdef\csname LBL##1\endcsname{#2}}
\def\Ref#1{\#ifundefined{LBL##1}{???}{\csname LBL##1\endcsname}}
\usepackage{hyperref}
\NewLabel{name1}{\noexpand\href{mailto:johnsmith#exmaple.com}{John Smith}}
\begin{document}
\Ref{name1}
\end{document}
The wider solution using \gdef is:
\documentclass{article}
\makeatletter
\def\NewLabel#1#2{\expandafter\gdef\csname LBL##1\endcsname{#2}}
\def\Ref#1{\#ifundefined{LBL##1}{???}{\csname LBL##1\endcsname}}
\usepackage{hyperref}
\NewLabel{name1}{\href{mailto:johnsmith#exmaple.com}{John Smith}}
\begin{document}
\Ref{name1}
\end{document}
Though I see why using \gdef instead of \xdef will avoid expanding the argument, which was previously causing the problem, I am not sure what negative consequences this could have. Is there a context where the change from \xdef to \gdef could cause problems?

Making a small modification to a LaTeX environment

I've been using \begin{figure} ... \end{figure} throughout my LaTeX document, but the default styling is ugly; namely, the figures are all left-aligned. Is there a way to redefine the "figure" environment so it automatically inserts some centering commands such as like this?:
\begin{figure} \begin{center}
\end{center} \end{figure}
Sure, I could use \newenvironment to define a "cfigure" environment, but that's undesirable. I don't want to go through and change all my "figures" to "cfigures" (and then later realise I wanted all the figures to be right-aligned and have to rename them all to "rfigures").
I could use \renewenvironment, but then I'd have to dig through the LaTeX source to find what the "figure" environment was originally defined as copy/paste it in.
I almost found what I wanted at this blog post, but the example there was for a command, not an environment.
\let\oldfigure\figure
\def\figure{\oldfigure\centering}
Another solution which works with the optional arguments.
Fixed.
\let\oldfigure\figure
\let\oldendfigure\endfigure
\def\figure{\begingroup \oldfigure}
\def\endfigure{\centering \oldendfigure \endgroup}
Fixed 2. It does work well with any options and any rules and \par inside.
\makeatletter
\let\oldfigure\figure
\def\figure{\#ifnextchar[\figure#i \figure#ii}
\def\figure#i[#1]{\oldfigure[#1]\centering}
\def\figure#ii{\oldfigure\centering}
\makeatother
As noted in another answer, you can't do the old trick of prepending commands to the end of the \figure macro because that will mess up the optional argument processing.
If an environment doesn't have arguments then it will work fine, but otherwise there's no straightforward way of doing this.
For your problem with the figures, try loading the floatrow package:
\usepackage{floatrow}
If will centre the content of your figures automatically.
Update: If you don't want to load a package, here's some code that will also do it. Note that it's specific to the figure environment, but the basic theme is: copy the original definition, parsing arguments the same way, then add whatever code you need at the end.
\makeatletter
\renewenvironment{figure}[1][\fps#figure]{
\edef\#tempa{\noexpand\#float{figure}[#1]}
\#tempa\centering
}{
\end#float
}
\makeatother
The \edef is required to fully expand \fps#figure before it's passed to the \#float macro.
How about:
\newenvironment{centeredfigure}{\begin{figure}\begin{center}}{\end{center}\end{figure}}
Note: untested.

Double-Spacing an ACM Proceedings Article in LaTeX

I am using the acm LaTeX template and I have trouble making my paper double spaced.
My LaTeX document looks like the following:
\documentclass{acm_proc_article-sp}
\usepackage{setspace}
\doublespacing
\begin{document}
...
\end{document}
When I compile the above document using pdflatex, I get the following error message on the line that I use the command \doublespacing:
Missing number, treated as zero \doublespacing
\linespread{2} should work. Doesn't need any packages, as far as I can tell, and you could change it to 1.9-spacing or 2.1-spacing, if you felt like it...
It looks like the acm_proc_article-sp class does some funky things that confuses the setspace package. In the preamble of your .tex document, add the following lines:
% Redefines \#ptsize to make setspace happy
\makeatletter
\renewcommand{\#ptsize}{0}
\makeatother
% Double-spaces the entire document
\usepackage{setspace}
\doublespacing
I have no idea why the acm_proc_article-sp class redefines \#ptsize to be empty.
I believe you want to use \usepackage{doublespace} to double-space your document. To put in a block of singlespacing, surround it with \begin{singlespace} and \end{singlespace}.
Ref: http://web.mit.edu/olh/Latex/ess-latex.html
The acm_proc_article-sp class seems to redefine \#ptsize to be empty for some reason. I don't know what \#ptsize is used for, so I don't want to mess with it. Using the \show command (see link text for more on this fantastic command), I see that \doublespacing is unpacked into
\setstretch{1.667} \ifcase \#ptsize \relax \setstretch{1.667} \or
\setstretch{1.618} \or \setstretch{1.655}\fi
In other words, \doublespacing is essentially equivalent to \setstretch{1.667}, with slightly different stretch factors if \#ptsize happens to be 1 or 2. So I think the most unobtrusive solution to your problem is replace \doublespacing by \setstretch{1.667}.
\documentclass{acm_proc_article-sp}
\usepackage{setspace}
\setstretch{1.667}
\begin{document}
...
\end{document}
I just tried out this command (in my preamble) for double spacing and it worked fine:
\usepackage{setspace}
\setstretch{2}
Alternative to the accepted solution: you can use \usepackage{setspace} if you include the line \doublespacing within your actual document (I have it right after the \maketitle command), instead of in your preamble. So something like:
\usepackage{fullpage}
\usepackage{setspace}
\begin{document}
\maketitle
\doublespacing
...
\end{document}
I'm not sure why this is different, but I think including it in the actual document automagically fills in the params you're missing.
Though this is an old thread, for those who stumble uppon:
What you have is actually correct and works. The problem is with the template that is being used. Probably it is overriding some command (like the \doublespacing).
This compiles and works fine for me:
\documentclass{article}
\usepackage{setspace}
\doublespacing
\begin{document}
testing
\end{document}
Don't do it. You need to follow the ACM conference proceedings article submission instructions, which don't want you to double-space the article anyway.

How to customize an existing LaTeX environment without interfering with other environments?

I'm using Sphinx for documenting a project. It produces LaTeX files from reStructuredText.
I would like to set a gray background color to the tips and notes, so I customized the notice environment after creating a graybox environment:
\definecolor{MyGray}{rgb}{0.80,0.80,0.80}
\makeatletter\newenvironment{graybox}{%
\begin{lrbox}{\#tempboxa}\begin{minipage}{\columnwidth}}{\end{minipage}\end{lrbox}%
\colorbox{MyGray}{\usebox{\#tempboxa}}
}\makeatother
\makeatletter
\renewenvironment{notice}[2]{
\begin{graybox}
\bf\it
\def\py#noticetype{#1}
\par\strong{#2}
\csname py#noticestart##1\endcsname
}
{
\csname py#noticeend#\py#noticetype\endcsname
\end{graybox}
}
\makeatother
Everything works fine except if I place a figure environment inside the notice environment. In that case, I get this error:
LaTeX Error: Not in outer par mode
Is there a way to set a gray background to that notice environment ?
This is a FAQ. It does not make sense to put a figure (or any other "float" which can move elsewhere in the output) inside a gray box; if you want your figure to contain a gray box, put the gray box environment inside the figure environment.
Thank you godbyk and Jouni for answering my question.
The problem is that I don't code directly in LaTeX. I write the documentation in restructured text and Sphinx output the LaTeX files.
But I found a solution: I redefine the figure environment to use the staticfigure from the flowfram package:
\usepackage{flowfram}
\definecolor{MyGray}{rgb}{0.80,0.80,0.80}
\makeatletter\newenvironment{graybox}{%
\begin{lrbox}{\#tempboxa}\begin{minipage}{\columnwidth}}{\end{minipage}\end{lrbox}%
\colorbox{MyGray}{\usebox{\#tempboxa}}
}\makeatother
\makeatletter
\renewenvironment{notice}[2]{
\begin{graybox}
\bf\it
\def\py#noticetype{#1}
\par\strong{#2}
\csname py#noticestart##1\endcsname
}
{
\csname py#noticeend#\py#noticetype\endcsname
\end{graybox}
}
\makeatother
\renewenvironment{figure}[6]{
\begin{staticfigure}
}{
\end{staticfigure}
}
PS: I had to put 6 to the number of arguments when redefining 'figure': if I don't do that it outputs some 'htbp' in the pdf files (I'm not a LaTeX expert. it's just the solution I found for this problem)
As Jouni correctly pointed out, figures and tables (i.e., floats) can be moved around, and your gray box can't contain them. To achieve the desired effect, you have two options:
Put your entire notice into a figure environment (so that the entire notice can be floated around on the page or to a new page if LaTeX so chooses).
Don't use a float (figure environment) -- just use \includegraphics to pop your image directly into the notice environment. You won't be able to use a caption with this non-figure, however, as captions only work inside a figure or table environment. If you want a caption associated with this image, you can use the caption package:
\documentclass{article}
\usepackage{caption}% let's us use captions outside of floats
\usepackage{lipsum}% provides filler text
\begin{document}
\lipsum[1]
\begin{center}
\includegraphics{mypic}
\captionof{figure}{This is my picture.}% makes a caption for non-floats
\label{fig:mypic}
\end{center}
\lipsum[2]
\end{document}
I haven't used Sphinx, so I'm afraid I can't help you too much with integrating this into their output.

Resources