pylatex Add Horizontal Line

1.6k Views Asked by At

If I have a simple document set up with pylatex...

import pylatex as pl

geometry_options = {
    "head": "1pt",
    "margin": "0.2in",
    "bottom": "0.2in",
    "includeheadfoot": False}

doc = pl.Document(geometry_options=geometry_options)

doc.append("text")

... how can I add a black horizontal seperation line of a certain thickness after the text block ?

1

There are 1 best solutions below

0
On

Found your unanswered question while asking the same thing. Harvesting from Gonzalo Medina's answer on a post for the TeX StackExchange, you could incorporate this using NoEscape. There's other examples you can use and you'll just need to insert them into the raw string (r"").

import pylatex as pl
from pylatex.utils import NoEscape
from pylatex.basic import NewLine

geometry_options = {
    "head": "1pt",
    "margin": "0.2in",
    "bottom": "0.2in",
    "includeheadfoot": False}

doc = pl.Document(geometry_options=geometry_options)

doc.append("text")
doc.append(NewLine())
doc.append(NoEscape(r"\noindent\rule{\textwidth}{1pt}"))
doc.append(NewLine())
doc.append("Text under the rule.")

I'm still figuring out LaTeX so I am sure there's a cleaner way than forcing a NewLine() like that, but it was the only way to have it spaced correctly.