2
a line of text\\
and another one\\
\indent line that should be indented \\
and this one should not be\\
\indent but this should

This works fine until i add \raggedright to the preamble. There are various post regarding similar problems but when I try the given solutions I end up with a paragraph where every line is indented. Is there something obvious I'm missing? Essentially I'm trying to reproduce the below layout with the following code

\subsection{Light}
\textit{Evocation cantrip}\\
\textbf{Casting Time:} 1 action\\
\textbf{Range:} Touch\\
\textbf{Components:} V, M (a firefly or phosphorescent moss)\\
\textbf{Duration:} 1 hour\\
You touch one object that is no larger than 10 feet in any dimension. Until the spell ends, the object sheds bright light in a 20-foot radius and dim light for an additional 20 feet. The light can be colored as you like. Completely covering the object with something opaque blocks the light. The spell ends if you cast it again or dismiss it as an action. \\
\indent If you target an object held or worn by a hostile creature, that creature must succeed on a Dexterity saving throw to avoid the spell.

but when i add \raggedright to the preamble the indent just disappears. Is there a way to add indentation to arbitrary lines and still have a ragged right edge?

enter image description here

  • Welcome to TeX.SX! In LaTeX you should not manually indent the first line of a paragraph and end the last line of a paragraph with \\ . Instead, just leave a blank line between paragraphs (or end them with \par which essentially is the same). – Skillmon Jul 31 '17 at 12:47
  • I don't really understand what you're trying to achieve in your code. Could you explain more in detail? – Bernard Jul 31 '17 at 13:21
  • Alternatively, you can set \leftskip=\parindent and \parindent=-\leftskip. – John Kormylo Jul 31 '17 at 13:31
1

Here are two quick ways (see below for a better way):

  1. \hspace{1em} following the \\

  2. Preferred would be to use a paragraph structure and not use \\ in general. Then you can set \parindent to the indent value.

The MWE:

\documentclass{article}
\raggedright
\begin{document}
\subsection{Light}
\textit{Evocation cantrip}\\
\textbf{Casting Time:} 1 action\\
\textbf{Range:} Touch\\
\textbf{Components:} V, M (a firefly or phosphorescent moss)\\
\textbf{Duration:} 1 hour\\
You touch one object that is no larger than 10 feet in any dimension. Until the spell ends, the object sheds bright light in a 20-foot radius and dim light for an additional 20 feet. The light can be colored as you like. Completely covering the object with something opaque blocks the light. The spell ends if you cast it again or dismiss it as an action. \\
\hspace{1em}%
If you target an object held or worn by a hostile creature, that creature must succeed on a Dexterity saving throw to avoid the spell.

\subsection{Light}
\textit{Evocation cantrip}\\
\textbf{Casting Time:} 1 action\\
\textbf{Range:} Touch\\
\textbf{Components:} V, M (a firefly or phosphorescent moss)\\
\textbf{Duration:} 1 hour\\
You touch one object that is no larger than 10 feet in any dimension. Until the spell ends, the object sheds bright light in a 20-foot radius and dim light for an additional 20 feet. The light can be colored as you like. Completely covering the object with something opaque blocks the light. The spell ends if you cast it again or dismiss it as an action. \par
\parindent=1em%
If you target an object held or worn by a hostile creature, that creature must succeed on a Dexterity saving throw to avoid the spell.
\end{document}

enter image description here

The problem with either quick fix is the, as a rule, \\ is a very poor and not recommended way to format lines. The problem with the 2nd \par approach is that each new subsection will have to \noindent all the header information, once \parindent is set to a non-zero value. So I think a third way is best...

A better way would be to cook it into a macro structure, and use the \par approach always (EDITED to permit multi-line header info):

\documentclass{article}
\usepackage[usestackEOL]{stackengine}
\raggedright
\strutlongstacks{T}
\newcommand\mysubsection[6]{%
\subsection{#1}
\setstackgap{S}{0pt}%
\Shortstack[l]{%
\parbox{\linewidth}{\strut\textit{#2}\strut}\\
\parbox{\linewidth}{\strut\textbf{Casting Time:} #3}\\
\parbox{\linewidth}{\strut\textbf{Range:} #4\strut}\\
\parbox{\linewidth}{\strut\textbf{Components:} #5\strut}\\
\parbox{\linewidth}{\strut\textbf{Duration:} #6}}%
\par\noindent\ignorespaces%
}
\parindent=1em%

\begin{document}

\mysubsection{Light}{Evocation cantrip}{1 action}{Touch}
  {V, M a firefly or phosphorescent moss) with
  a multi-line item tha goes blah blah blah blah}{1 hour}
%
You touch one object that is no larger than 10 feet in any dimension. Until the 
spell ends, the object sheds bright light in a 20-foot radius and dim light 
for an additional 20 feet. The light can be colored as you like. Completely 
covering the object with something opaque blocks the light. The spell ends 
if you cast it again or dismiss it as an action. 

If you target an object held or worn by a hostile creature, that creature 
must succeed on a Dexterity saving throw to avoid the spell.
\end{document}

enter image description here

  • Is there any reason to chose one of these over the other? – Spade Jul 31 '17 at 12:51
  • @Spade As a rule using \\ is a very frowned on approach, so for a quick fix, I would use the \par approach. However, you will be forced to use \noindent a lot if you do, unless you place it in a macro approach, like I show in my edited revision. – Steven B. Segletes Jul 31 '17 at 13:02
  • Two questions. What does MWE stand for? Second question (maybee a separate question?) but you macros both have the issue that if I have a line (eg. the components line) that is really long and my page layout is two columns the line doesnt wrap but instead sticks out into the other column. This doesn't happen when I use my "ugly" way. – Spade Jul 31 '17 at 14:37
  • @Spade MWE is "minimum working example" to denote a self-contained small, but complete LaTeX code that demonstrates the issue. I show in my addendum how one could do multi-line items using a \Longunderstack with manual line breaks. Alternately, one could use a \parbox of a specified length as the entry. – Steven B. Segletes Jul 31 '17 at 14:43
  • @Spade I have edited my ADDENDUM to automatically handle multi-line input, without manual formatting. – Steven B. Segletes Jul 31 '17 at 14:50
2

Usually \RaggedRight from ragged2e is better instead of \raggedright for long term ragged right typesetting.

It also allows to specify a parindent.

\documentclass{article}
\usepackage{ragged2e}

\newcommand{\manualsection}[3]{%
  % #1 = title
  % #2 = subtitle
  % #3 = items
  \subsection[#1]{%
    \parbox{\columnwidth}{
      #1\\
      \normalfont\normalsize
      \textit{#2}\\[\smallskipamount]
      #3%
    }%
  }%
}
\newcommand{\secitem}[2]{%
  \textbf{#1:} #2%
}

\setcounter{secnumdepth}{1} % only number sections
\setlength{\RaggedRightParindent}{\parindent}
\RaggedRight


\begin{document}

\manualsection{Light}{Evocation cantrip}
  {\secitem{Casting Time}{1 action}\\
   \secitem{Range}{Touch}\\
   \secitem{Components}{V, M (a firefly or phosphorescent moss)}\\
   \secitem{Duration}{1 hour}}

You touch one object that is no larger than 10 feet in any dimension.
Until the spell ends, the object sheds bright light in a 20-foot
radius and dim light for an additional 20 feet. The light can be
colored as you like. Completely covering the object with something
opaque blocks the light. The spell ends if you cast it again or
dismiss it as an action.

If you target an object held or worn by a hostile creature, that
creature must succeed on a Dexterity saving throw to avoid the spell.

\end{document}

enter image description here

Your Answer

By clicking “Post Your Answer”, you agree to our terms of service, privacy policy and cookie policy

Not the answer you're looking for? Browse other questions tagged or ask your own question.