Warning using \recalctypearea after \spacing [closed] - latex

Closed. This question does not meet Stack Overflow guidelines. It is not currently accepting answers.
This question does not appear to be about programming within the scope defined in the help center.
Closed 7 years ago.
Improve this question
I use DIV=10 to set the type area, because the calculated type area would have too large margins for me.
I have read that you should use \recalctypearea after setting the font and line spacing.
So first: does this also make sense, when I have a defined DIV-value instead of DIV=calc?
If yes, here is my actual question: I use \spacing{1.2}, because \onehalfspacing seems to be a little bit too large for me.
I get the warning "Package typearea Warning: \typearea used at group level 2. Using \typearea inside any group, e.g. environments, math mode, boxes, etc. may result in many type setting problems. You should move the command \typearea outside all groups on input line 11."
If I use \usepackage[onehalfspacing]{setspace} instead of \usepackage{setspace} \spacing{1.2}, I don't get this warning.
Should I ignore the warning or what should I do?
MWE:
\documentclass[a4paper,12pt,headinclude=false, footinclude=false, BCOR=8mm,DIV=10]{scrreprt}
\usepackage[oldstyle]{libertine}
\setmainfont[Mapping=tex-text,Ligatures={Common},Numbers=OldStyle]{Linux Libertine O}
\setsansfont[Numbers=OldStyle]{Linux Biolinum O}
\setmonofont[Scale=MatchLowercase]{Linux Libertine Mono O}
\usepackage{setspace}
\spacing{1.2}
\recalctypearea
\begin{document}
Text
\end{document}

Package typearea
The command \recalctypearea ist just an abbreviation for \typearea[current]{last} which means, that the page layout is calculated again by the current binding correction (BCOR, first parameter) and the last DIV value (second parameter), see KOMA-script documentation p. 37
The BCOR and DIV value must be set beforehand. But, all (normal) ways to set these options already do a page layout calculation afterwards. So, if you want DIV=10, then use one of the following ways:
% Choosing a KOMA-script class
\documentclass[DIV=10]{scrreport}
% During loading the package, if another documentclass is used
\usepackage[DIV=10]{typearea}
% Or after loading the package with one of these
% a)
\KOMAoptions{DIV=10}
% b)
\typearea{10}
So, \recalctypearea should only be required if DIV=calc has been used and fonts or page sizes have been changed since this option has been set the last time.
Interaction with package spacing
Setting the DIV parameter affects the whole page. So, you can't change it within a group, e.g. the itemize environment \begin{itemize}...\end{itemize}.
Calling \spacing{1.2} opens a new group (environment) which is closed by \endspacing. The spacing will only be changed within this environment. Something which cannot be done (normally) for the page layout. Don't ignore the warning. To change the line spacing, use the macro \linespread instead, e.g.:
\linespread{1.25} % within preamble
should give a line spacing of 1.2*1.25 = 1.5. (1.2 is the normal base line skip). For more information see also here.
Further hints
Please note, that direct calls of \spacing macros is not recommended. Use
\begin{spacing}{1.2}
Your Text
\end{spacing}
instead because \end{spacing} will check if the right environment is closed (better error reporting).
For some details, here is the code of the spacing environment:
% quote from setspace.sty, line 524 ff, fetched from CTAN at 2015-11-17
\newenvironment{spacing}[1]{%
\par
\begingroup % moved from \endspacing by PGBR 29-1-91
\setstretch {#1}%
}{%
\restore#spacing
}
The first code block
{%
\par
\begingroup % moved from \endspacing by PGBR 29-1-91
\setstretch {#1}%
}
is called at \begin{spacing}{...} and starts a new paragraph (\par) and opens a new group (\begingroup). Within a group, changes to LaTeX variables/ macros (and so on) will only have a local effect. The second code block is called at \end{spacing} which calls an appropiate \endgroup.

Related

How to automatic break lines in latex?

I have searched but nothing useless, only "use \newline" or "use \".
I'm creating a simple latex document to store any texts instead of using .txt, and the problem is that the pdf document contains the lines going towards right until they go out of the paper.
I'm using this simple code
\documentclass[a4paper]{article}
\usepackage{geometry}
\geometry{
a4paper,
total={170mm,257mm},
left=5mm,
top=20mm,
}
\begin{document}
\section{Text 1}
Loremipsumdolorsitamet,consecteturadipiscingelit,seddoeiusmodtemporincididuntutlabore etdoloremagnaaliqua.Utenimadminimveniam,quisnostrudexercitationullamcolaborisnisiutaliquipexeacommodoconsequat.Duisauteiruredolorinreprehenderitinvoluptatevelitessecillum doloreeufugiatnullapariatur.Excepteursintoccaecatcupidatatnonproident,suntinculpaquiofficiadeseruntmollitanimidestlaborum.
\end{document}
Since latex sees it as a one word, it refuses to break it since it doenst know its hyphenation. But I would like to allow latex to break it regardless. Any thoughts ?
Remarks: I already have used:
\hspace{0pt}
\leavevmode\nobreak\hspace{0pt}
\mbox{Loremip...larorum.}
Nothing worked.
I think I got why nothing worked. See my code below, that I managed to compile successfully after editing your MWE.
You basically have two ways to force hyphenation here.
As in the comment by SamCarter, you manually split words within text, just using \- where necessary. I did it below in line 18 (6 from bottom).
You add to your preamble the command \hyphenation{word-to-split}: I did this below to hyphenate the word in line 20 (4 from bottom). Notice that, in this case, you use - instead of \- within the braces {} enclosing the argument.
\documentclass[a4paper]{article}
\usepackage{geometry}
\geometry{
a4paper,
total={170mm,257mm},
left=5mm,
top=20mm,
}
\hyphenation{Duisauteiruredolorinre-prehenderitinvoluptatevelitesse-cillum doloreeufugiatnullapariatur}
\begin{document}
\section{Text 1}
Loremipsumdolorsitamet, consecteturadipiscingelit,
seddoeiusmodtemporincididuntutlaboreetdoloremagna.
Uten\-imadminimveniam,
quisnostrudexercitationullamcolaborisnisiutaliquipexeacommodoconsequat.
Duisauteiruredolorinreprehenderitinvoluptatevelitessecillumdoloreeufugiatnullapariatur.
Excepteursintoccaecatcupidatatnonproident,
suntinculpaquiofficiadeseruntmollitanimidestlaborum.
\end{document}
Finally, if the full stop character . is not followed by a space, two separate words may be interpreted as one and the command \hyphenation may not work as expected. Not sure that this was the detail making you write that nothing worked, but be careful to this too.

Any way to keep R Markdown from putting a LaTeX environment in a new paragraph?

Environments like align and gather are pretty clearly designed for use within a paragraph of LaTeX text, as two line breaks between the document text and the start of the math environment inserts an egregious two paragraph's worth of vertical white space. Markdown, though, always starts any LaTeX environment two lines below the text that's above it, even if you begin the environment on the very same line of the markdown code/text, and even if you put 2 spaces before it in order to add a single line break. Since there's no multiline math dislay native to markdown, this poses a dilemma.
Running \vspace{-\baselineskip} before the environment compensates well enough, but of course it would be better to just tell markdown not to insert the line breaks in the first place. Is that possible? And if not, then what would be the easiest way to automatically run \vspace{-\baselineskip} before the beginning of each align (and/or align*, gather, gather*, etc.) environment?
MWE:
---
output:
pdf_document:
keep_tex: 1
---
The following environment will get marked up with an extra two lines between it and
this text, putting it on a new paragraph and creating a lot of whitespace above it,
whether or not there's any line breaks in the markdown code:
\begin{gather*}
A \\ B
\end{gather*}
This can of course be hackily corrected by subtracting vertical space:
\vspace{-\baselineskip} \begin{gather*}
A \\ B
\end{gather*}
The best you can do in this situation is to automatically insert \vspace{-\baselineskip} at the start of every specific environment using the etoolbox package:
---
output:
pdf_document:
keep_tex: 1
header-includes:
- \usepackage{etoolbox}
- \AtBeginEnvironment{gather}{\vspace{-\baselineskip}}
- \AtBeginEnvironment{gather*}{\vspace{-\baselineskip}}
---
The following environment will get marked up with an extra two lines between it and
this text, putting it on a new paragraph and creating a lot of whitespace above it,
whether or not there's any line breaks in the markdown code:
\begin{gather*}
A \\ B
\end{gather*}
This can of course be hackily corrected by subtracting vertical space:
\begin{gather*}
A \\ B
\end{gather*}
This, however, is not optimal, as the gap inserted by the environment depends on the amount of text ending the preceding paragraph. As a result of Pandoc's processing, the amount is always the same (\abovedisplayskip), so it may be "better" to use
header-includes:
- \usepackage{etoolbox}
- \AtBeginEnvironment{gather}{\vspace{\dimexpr-\baselineskip-\abovedisplayskip}}
- \AtBeginEnvironment{gather*}{\vspace{\dimexpr-\baselineskip-\abovedisplayskip}}
You'll have to do this for all amsmath-related display alignments.

Redefining sectioning commands in latex, issues with references and labels

I'm trying to change the appearance of one of the native sectioning commands in LaTeX. But after doing so, latex cannot handle references as expected.
The code given later is expected to output a document with the text
1 One
See section 2.
2 Two
See section 1.
But instead I get the following.
1 One
See section .
2 Two
See section .
What can I change in the renewed command, such that the references will work again.
The code for the document is as follows:
\documentclass{article}
\newcounter{seccnt}
\renewcommand{\section}[1]{\vspace{2em}\stepcounter{seccnt} \theseccnt~ {\Large #1}\vspace{0.5em}}
\begin{document}
\section{One}
\label{secOne}
See section \ref{secTwo}.
\section{Two}
\label{secTwo}
See section \ref{secOne}.
\end{document}
I think you need to use \refstepcounter instead of \stepcounter, so that the reference is stored.

LaTeX: Redefining starred command

I want to redefine the \part* command so that it automatically adds a contents line. This proves difficult since I want to reuse the original \part* command inside my starred version.
Normally (i.e. for unstarred commands) I would do it like this:
\let\old#part\part
\renewcommand\part[2][]{
\old#part[#1]{#2}
… rest of definition}
That is, I would save the original definition of \part in \old#part and use that.
However, this doesn’t work for starred commands since they don’t define a single lexeme (unlike the \part command in the example above). This boils down to the following question: How can I save a starred command?
Notice that I already know how to redefine a starred command itself, using the \WithSuffix command from the suffix package. This isn’t the problem.
There is no \part* command. What happens is the \part command takes a look at the next character after it (with \#ifstar) and dispatches to one of two other routines that does the actual work based on whether there's an asterisk there or not.
Reference: TeX FAQ entry Commands defined with * options
Thanks to #smg’s answer, I’ve cobbled together a solution that works perfectly. Here’s the complete source, along with explanatory comments:
% If this is in *.tex file, uncomment the following line.
%\makeatletter
% Save the original \part declaration
\let\old#part\part
% To that definition, add a new special starred version.
\WithSuffix\def\part*{
% Handle the optional parameter.
\ifx\next[%
\let\next\thesis#part#star%
\else
\def\next{\thesis#part#star[]}%
\fi
\next}
% The actual macro definition.
\def\thesis#part#star[#1]#2{
\ifthenelse{\equal{#1}{}}
{% If the first argument isn’t given, default to the second one.
\def\thesis#part#short{#2}
% Insert the actual (unnumbered) \part header.
\old#part*{#2}}
{% Short name is given.
\def\thesis#part#short{#1}
% Insert the actual (unnumbered) \part header with short name.
\old#part*[#1]{#2}}
% Last, add the part to the table of contents. Use the short name, if provided.
\addcontentsline{toc}{part}{\thesis#part#short}
}
% If this is in *.tex file, uncomment the following line.
%\makeatother
(This needs the packages suffix and ifthen.)
Now, we can use it:
\part*{Example 1}
This will be an unnumbered part that appears in the TOC.
\part{Example 2}
Yes, the unstarred version of \verb/\part/ still works, too.

Latex Multiple Linebreaks

I use LaTeX to type up programming homeworks for classes. I need to do this:
my line of text blah blah blah
new line of text with blank line between
I know I can use double slash to break lines \\, but LaTeX will only take the first line break (complains about more) and starts a new line, it produces this :
my line of text blah blah blah
new line of text with blank line between
How can I get that extra line break in there so I can have space between my lines of text?
Line break accepts an optional argument in brackets, a vertical length:
line 1
\\[4in]
line 2
To make this more scalable with respect to font size, you can use other lengths, such as \\[3\baselineskip], or \\[3ex].
Do you want more space between paragraphs? Then you can change the parameter \parskip.
For example, try
\setlength{\parskip}{10pt plus 1pt minus 1pt}
This means that the space between paragraphs is usually 10pt, but can grow or shrink by up to 1pt. This means you give LaTeX the ability to change it up to one 1pt in order to achieve a better page layout. You can remove the plus and minus parts to make it always your specified length.
If you are trying to display source code, try the listings package or use verbatim. If you are trying to typeset pseudocode, try the algorithm package.
Insert some vertical space
blah blah blah \\
\vspace{1cm}
to scale to the font, use ex (the height of a lowercase "x") as the unit, and there are various predefined lengths related to the line spacing available, you might be particularly interested in baselineskip.
You can use the setspace package which gives you spacing environments, e.g.:
\documentclass{article}
\usepackage{setspace}
\begin{document}
\doublespace
my line of text blah blah blah
new line of text with blank line between
\end{document}
Or use a verbatim environment to control the layout of your code precisely.
For programs you are really better off with a verbatim or alltt environment, but if you want a blank line that LaTeX will not bitch about, try
my line of text blah blah blah\\
\mbox{ }\\ %% space followed by newline
new line of text with blank line between
While verbatim might be the best choice, you can also try the commands \smallskip , \medskip or guess what, \bigskip .
Quoting from this page:
These commands can only be used after
a paragraph break (which is made by
one completely blank line or by the
command \par). These commands output
flexible or rubber space,
approximately 3pt, 6pt, and 12pt high
respectively, but these commands will
automatically compress or expand a
bit, depending on the demands of the
rest of the page
I find that when I include a blank line in my source after the \\ then I also get a blank line in my output. Example:
It's time to recognize the income tax as another horrible policy mistake like banning beer, and to return to the tax policies that were correct in the Constitution in the first place. Our future depends on it.
\\
Wherefore the 16th Amendment must forthwith be repealed.
However you are correct that LaTeX only lets you do this once. For a more general solution allowing you to make as many blank lines as you want, use \null to make empty paragraphs. Example:
It's time to recognize the income tax as another horrible policy mistake like banning beer, and to return to the tax policies that were correct in the Constitution in the first place. Our future depends on it.
\null
\null
\null
Wherefore the 16th Amendment must forthwith be repealed.
\\\\
This works on pdfLatex. It creates 2 new lines for you.
Maybe try inserting lines with only a space?
\ \\
\ \\
This just worked for me:
I was trying to leave a space in the Apple Pages new LaTeX input area. I typed the following and it left a clean line.
\mbox{\phantom{0}}\\

Resources