How to Indent Text as if it's in a List

Let's say I have this sample text:

1. Lorem ipsum dolor sit amet, consecteur adipiscing elit. Ut purus elit, vestibulum ut,
   adipiscing

In LaTeX output when there is too much text to fit in one line and it's in a list, it will automatically indent so it alignts with the text above, as you can see with the code block I made. What if I don't want to make a list and I want to do this instead:

Sample text: Lorem ipsum dolor sit amet, consecteur adipiscing elit. Ut purus elit,
             vestibulum ut, adipiscing

I still want the text to align with "Lorem ipsum", and I'm not sure how to automatically do that.

You can use a special syntax in markdown to keep your indentation. See

However, spaces in markdown does not exactly means spaces in HTML so you need more in markdown

---
title: test
output: pdf_document
---

# line block

See https://pandoc.org/MANUAL.html#extension-line_blocks

| Sample text: Lorem ipsum dolor sit amet, consecteur adipiscing elit. Ut purus elit,
|                   vestibulum ut, adipiscing

Hope it helps

Thanks, that works. But my problem with that method is that I have to manually indent the text. Sometimes I'll have one line of text on my text editor that's very long but on the resulting document it renders as two lines so I have to manually indent the text. If I'm doing a list, I don't have to worry about that because it indents new lines automatically.

Is there a way to make an unordered list but change the bullet character to something else (like "Sample text:")?

What about making a table and tweak style to have no border and align as you want ?
Don't really know for PDF how that works, but should be possible.

Otherwise, Pandoc offers several type of list from Markdown syntax (Pandoc - Pandoc User’s Guide) among them Definition List Pandoc - Pandoc User’s Guide if you set md_extensions: +definition_lists in YAML format. Maybe that helps.

However to replace bullet by test you would probably need to use some LaTeX preamble somehow.

The definition list seemed promising but its flaw is that you can have only one line for the definition. I figured out how to change the LaTeX itemize character but the issue with that is it doesn't start exactly at the beginning of text width, it's treated like a bullet list. As for the table idea, I like the idea but I'm not sure how to do it. I use pander for tables and I've also used kable, but I don't know how to have no borders. I looked online and couldn't find it.

Seems like you can do that using kableExtra or just kable (Remove ALL horizontal lines in a table · Issue #413 · haozhu233/kableExtra · GitHub)

Changing the color of LaTeX table is also a way : r - Is there a way to make a kable without lines/borders for pdf? - Stack Overflow

And there are more results

Mixing all this you should find what you need.

1 Like

Thanks, it worked for me:

one = c("Sample text:")
two = c("Lorem ipsum alor si adet asroetns toaentsa oentsoiesrantaroiesnt asornt sraoetnasroti nratoientarent rastenrasotnrats")

df = data.frame(one, two)

kable(df, booktabs = TRUE, col.names = NULL) %>%
  kable_styling(full_width = TRUE, position = "left") %>%
  column_spec(1, width = "5em" ) %>%
  sub("\\\\toprule", "", .) %>%
  sub("\\\\bottomrule", "", .)

I also added a function in my package amaryaml to make it easier.

1 Like

This topic was automatically closed 7 days after the last reply. New replies are no longer allowed.

If you have a query related to it or one of the replies, start a new topic and refer back with a link.