简体   繁体   中英

How can I put the title and author closer together in PyLaTeX?

I'm using PyLaTeX as a means to generate pdfs (as part of a flask web app), and I can't get the title and author to be at a distance other than the the default one.

My code as of now looks like this (this works as a means of collapsing the date section)

doc.preamble.append(Command('title', f"This is my personalized title with a {variable}"))
doc.preamble.append(Command('author', "This is the author"))
doc.preamble.append(Command('date', NoEscape(r'\vspace{-3ex}'))) #didn't want a date
doc.append(NoEscape(r'\maketitle'))

Trying it with vspace

The issue is that the same \\vspace{-3ex} seems to do nothing at all if I place it inside the author command (the space between title and author stays the same). Also placing it inside the title changes the space above the title, not below.

doc.preamble.append(Command('title', NoEscape(r'\vspace{4.0cm}' + f"Title with {variable}"))) #adds space on top
doc.preamble.append(Command('author', NoEscape(r'\vspace{-3.0cm}' + "Author"))) #this changes nothing

Trying it with titling

I've also tried to use the titling LaTeX package, but I can't get it to work from PyLaTeX. I think it imports it correctly, but then I can't for example change the posttittle like the other stuff:

doc.packages.append(Package(titling)) #this seems fine
doc.preamble.append(Command('posttitle','\vspace{-3.0cm}')) #things like this crash the compiler
...
doc.preamble.append(NoEscape(r'\posttittle{\vspace{-3.0cm}}')) #things like this don't work either

Though I may not be using the titling properly inside of PyLaTeX (I learned most of all this yesterday, so hm...).

Okay, as @Patrick Artner pointed out, the order matters.

doc.preamble.append(Command('title', NoEscape(f"Title with {variable}" + r'\vspace{-1cm}')))

From the docs I understood that \\vspace affected the line it appeared in (independently of where on the line it was placed). It seems not (having \\vspace at the beginning changes the height of the title, but having it at the end changes the space between the title and the author).

The technical post webpages of this site follow the CC BY-SA 4.0 protocol. If you need to reprint, please indicate the site URL or the original address.Any question please contact:yoyou2525@163.com.

 
粤ICP备18138465号  © 2020-2024 STACKOOM.COM