TeX - LaTeX Asked by Olon on June 28, 2021
I have defined a custom text font command using :
DeclareTextFontCommand{desc}{
fontsize{11pt}{11pt}
fontseries{light}selectfont
vspace{10px}
}
And I have used it like that :
desc{Lorem ipsum dolor sit amet, consectetur adipiscing elit. Sed at tempor ex. Praesent a luctus enim. Nam mauris odio, ornare at egestas ut, mollis aliquet est. Nunc a rutrum tortor. Suspendisse et odio rutrum, porta ipsum non, fermentum turpis.}
I expected to have a 10 px space after the paragraph, but the space is added after the first line :
Also, why are the second and third lines are not aligned with the first line since I removed the indent of the paragraph? Those are shifted left in the margin of the page.
vspace
adds the space at the point where it's called. So, for example if you write
Foo
vspace{1in}
Foo
The space goes betwen paragraphs, while
Foo
vspace{1in}
Foo
puts it after the line on which the first Foo
appears. So surely, we should see, if we have
Foo
desc{Foo}
that the space comes between the paragraphs, right? Except that you're using DeclareTextFontCommand
which does a little bit more. In particular, it does:
def DeclareTextFontCommand #1#2{%
DeclareRobustCommand#1[1]{%
ifmmode
nfss@text{#2##1}%
else
hmode@bgroup % ❶
text@command{##1}%
#2check@icl ##1check@icr
expandafter
egroup fi
}
❶ is the critical line here. hmode@bgroup
leaves vertical mode (so it begins the paragraph) and then begins a group. So your vspace
is being output after the paragraph begins and comes after the first line.
Most likely, what you want is not to use DeclareTextFontCommand
at all. Assuming that you want to use this as a marker at the beginning of paragraphs, you could instead do:
NewDocumentCommand{ m }{%
par
vspace{10px}
{%
fontsize{11pt}{11pt}%
fontseries{light}selectfont
#1
}%
}
to get your desired effect.
(Side note, I'd not seen px
as a unit in TeX before. It's apparently equivalent to bp
or the PostScript point of 1/72 in. It's not mentioned in The TeXbook as far as I know. Apparently an eTeX enhancement as it's an illegal unit if I use tex
but is available with pdftex
and any of the LaTeX engines which all require eTeX.)
Answered by Don Hosek on June 28, 2021
Environments are easier to use and and fixed my problem. The second {} contains the styles to apply before the text and the third {} contains the styles to apply after the text.
newenvironment{desc}{%
fontsize{11pt}{11pt}%
fontseries{light}selectfont%
begin{spacing}{1.1}%
}{end{spacing}vspace{10px}}
Adding % after each line fixed my second problem. Without these, whitespace would shift the text right.
Answered by Olon on June 28, 2021
Get help from others!
Recent Questions
Recent Answers
© 2024 TransWikia.com. All rights reserved. Sites we Love: PCI Database, UKBizDB, Menu Kuliner, Sharing RPP