19

What do I write at the end of a paragraph if my text is a couple letters short of being flush from left to right and I want the last line stretched slightly so that no empty space is left that the end?

If I do the obvious,

\documentclass{article}
\begin{document}

X Blah blah blah blah blah blah blah blah blah Blah blah blah blah blah
blah blah  blah  blah blah Blah blah blah blah blah blah blah blah. 

Y Blah blah blah blah blah blah blah blah blah Blah blah blah blah blah
blah blah blah blah blah Blah blah blah blah.

A Blah blah blah blah blah blah blah blah blah Blah blah blah blah blah
blah blah  blah  blah blah Blah blah blah blah blah blah blah blah. 
\linebreak
% Unwanted empty line appears here

B Blah blah blah blah blah blah blah blah blah Blah blah blah blah blah
blah blah blah blah blah Blah blah blah blah.
\end{document}

then an extra empty line appears after that and separate the paragraphs. How do I prevent this empty line from appearing?

To clarify: I would like to have two paragraphs, not one. Indeed getting rid of the paragraph break would remove the empty line between paragraphs when using manual line-break. But that would make A and B one paragraph instead of two.

See standard formatting in paragraphs X and Y.

Is there a way which does not require use of braces? Using braces might annoy those with whom I share article who want to revert to original formatting. Deleting all manual code of one type can be automated; but removing braces must be done manually since they are used in many places.

EDIT: Have any attempts to turn the command into one line added after the paragraph desired to be formatted or to automate this for whole document where last line has whitespace shorter than a certain length, like was discussed in Avoid just nearly filled last lines, been successful?

21

if the last line of your paragraph is really nearly full, you can get it to end flush right by the following approach.

  • wrap the paragraph in braces.

  • end the paragraph with these commands (inside the braces):

    \unskip\parfillskip 0pt \par
    

update: a mechanism that doesn't require braces.

  • before the paragraph, insert

    \startsquarepar
    
  • at the end of the paragraph, insert

    \stopsquarepar
    
  • define these two commands in the preamble as follows:

    \newcommand{\startsquarepar}{%
        \par\begingroup \parfillskip 0pt \relax}
    \newcommand{\stopsquarepar}{%
        \par\endgroup}
    

it's not necessary to have blank lines either before or after either of these commands (the grouping and included \par ensures that that's not a problem), but readability and "good practice" suggests that a blank line before \startsquarepar and one after \stopsquarepar is a good idea.

blank lines within the scope of \startsquarepar and \stopsquarepar will start new paragraphs as expected, and all paragraphs within this scope will end flush right -- whether or not there's the right amount of material in each paragraph to avoid excessive spacing.

why didn't i use \begin... and \end...? while there are no "strings" attached to \begin..., latex has co-opted the use of \end... for its own purposes in defining environments. if you really prefer the \begin ... \end terminology and environment syntax, it's easy to transform the two command definitions given into a single environment definition. (but left as an exercise to the reader.)

edit: one final suggestion from egreg's comment (to keep it from getting lost).

{{\parfillskip0pt\par}} can be a useful for a manual solution as it doesn't need bracing the paragraph.

  • This works! Thank you. But to clarify my question, is there a second way, which does not require use of braces, however? Doing this might very well annoy those with whom I share article who want to revert to original formatting. Deleting all manual \linebreaks can be automated; but removing braces must be done manually since they are used in many places. If I do this without braces of course it applies to the whole document (which would not be a bad thing in some cases were it is coincidence that all lines are almost full-- but not in general). – user34902 Aug 11 '13 at 6:31
  • @user34902 -- a "start/stop" approach is added -- see update. note that context uses \start.../\stop... terminology, and i don't know whether context has attached any "strings" (as latex has to \begin.../\end...). – barbara beeton Aug 11 '13 at 12:47
  • It works well. Thank you. One clarification. Do you think that these two commands can this be written as one code box or line that I paste entirely at the end of the desired paragraph if I paste it without spacing right after the last period in the paragraph? (I am also investigating an automatic code to insert at the beginning of the document, such as that discussed in tex.stackexchange.com/questions/41412/…, which does this for all paragraphs whose last line is shorter than x but that is another question. – user34902 Aug 11 '13 at 14:13
  • 6
    {{\parfillskip0pt\par}} can be a useful for a manual solution as it doesn't need bracing the paragraph. – egreg Aug 11 '13 at 17:23
  • egreg, that was perfect! exactly what I am looking for in single paragraphs. Together with barbara beeton's nice solution for several paragraphs in a row, this gives perfect set of manual solutions for every case, which are easily reversed by editors. – user34902 Aug 11 '13 at 17:40
9

It is as simple as getting rid of the empty line in your code

\documentclass{article}
\begin{document}
Blah blah blah blah blah blah blah blah blah Blah blah blah blah blah blah blah  
blah  blah blah Blah blah blah blah blah blah blah blah. \linebreak
Blah blah blah blah blah blah blah blah blah Blah blah blah blah blah blah blah blah 
blah blah Blah blah blah blah.
\end{document}

Which produces

output

Empty line ends the paragraph, just like the \par command. \linebreak switches to next line within the same paragraph.

  • This is how I do it in one paragraph of course, as the code was intended. But what if I want two paragraphs, without empty line between them. In original formatting, paragraphs are not separated by empty lines. I want to merely justify the last almost full line of the first paragraph for better appearance in some cases without doing anything else anywhere to original formatting. – user34902 Aug 11 '13 at 6:43

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.