Using an environment leaves a line by default.

  • Context: MHB 
  • Thread starter Thread starter caffeinemachine
  • Start date Start date
  • Tags Tags
    Line
Click For Summary
SUMMARY

The discussion focuses on controlling spacing in LaTeX when using environments such as the center environment. Users encounter default spacing issues that create unwanted gaps before and after the content. Solutions include using the \hspace command for precise spacing and employing plain TeX commands for better control. Specific examples demonstrate how to achieve desired layouts, such as centering text on the same line or on separate lines without additional spacing.

PREREQUISITES
  • Understanding of LaTeX document structure
  • Familiarity with LaTeX spacing commands like \hspace and \hfill
  • Knowledge of plain TeX commands for advanced formatting
  • Experience with LaTeX environments, particularly the center environment
NEXT STEPS
  • Research LaTeX spacing commands, focusing on \hspace and \hfill
  • Explore plain TeX commands for advanced text formatting
  • Learn about creating custom environments in LaTeX
  • Investigate LaTeX document classes and their impact on spacing
USEFUL FOR

LaTeX users, document designers, and technical writers seeking to refine text formatting and control spacing in their documents.

caffeinemachine
Gold Member
MHB
Messages
799
Reaction score
15
Suppose in LaTeX I write:

This the first line. begin{center}This is the centered line. end{center}.
What I get is:

This is the first line

This is the centered line.​
But suppose I want this:


This is the first line.~~~~~~~~~~~~~~~~This is the centered line.

(Here tilde is white space. Some how simply using spacebar wasn't working.)

What is the way to do it? My problem is that when I open any environment a fixed amount of space is always left before and after the contents of the contents of the environment. How can I control the amount of space left?
 
Physics news on Phys.org
Well, \hspace is one way. You could write

Code:
This is the first line. $\hspace{3in}$ This is the centered line.

producing

This is the first line. $\hspace{3in}$ This is the centered line.

Then you could play around with the spacing command. It's a rather bone-headed way to do it, but also quick and dirty. It almost looks like you're wanting a two-column environment. Is that the case?
 
caffeinemachine said:
Suppose in LaTeX I write:

This the first line. begin{center}This is the centered line. end{center}.
What I get is:

This is the first line

This is the centered line.​
But suppose I want this:


This is the first line.~~~~~~~~~~~~~~~~This is the centered line.

(Here tilde is white space. Some how simply using spacebar wasn't working.)

What is the way to do it? My problem is that when I open any environment a fixed amount of space is always left before and after the contents of the contents of the environment. How can I control the amount of space left?
One way to do this would be to go back to basics, and use the plain TeX spacing commands instead of the LaTeX center environment.

It's not clear to me whether you want "This is the centered line" to have a line to itself, but without the extra spacing above and below that the center environment provides, or whether you actually want "This is the centered line" to be on the same line as "This is the first line."

If it is to have a line to itself, that is easily done as follows:
Code:
This is the first line. \\
\hspace*{\fill} This is the centered line. \hspace*{\fill} \\
This is the next line.
That will give:

This is the first line.
This is the centered line.​
This is the next line.

But if you want both things to be on the same line, there is then a further question. Do you want "This is the centered line" to be centred on the whole line, or do you want it to be centred in the part of the line to the right of "This is the first line"? In the first case, you need this:
Code:
\leavevmode
\rlap{This is the first line.} \hfill This is the centered line. \hspace*{\fill} \\
This is the next line.

In the second case, you need this:
Code:
This is the first line. \hfill This is the centered line. \hspace*{\fill} \\
This is the next line.

The outcomes from those will look something like this:
Code:
This is the first line....This is the centered line........|
This is the next line...............|
.............                      ...|
.............                      ...|
.............                      ...|
This is the first line....            ...This is the centered line.......|
This is the next line...............|
(the bar denotes where the right margin starts).
 
Opalg said:
One way to do this would be to go back to basics, and use the plain TeX spacing commands instead of the LaTeX center environment.

It's not clear to me whether you want "This is the centered line" to have a line to itself, but without the extra spacing above and below that the center environment provides, or whether you actually want "This is the centered line" to be on the same line as "This is the first line."

If it is to have a line to itself, that is easily done as follows:
Code:
This is the first line. \\
\hspace*{\fill} This is the centered line. \hspace*{\fill} \\
This is the next line.
That will give:

This is the first line.
This is the centered line.​
This is the next line.

But if you want both things to be on the same line, there is then a further question. Do you want "This is the centered line" to be centred on the whole line, or do you want it to be centred in the part of the line to the right of "This is the first line"? In the first case, you need this:
Code:
\leavevmode
\rlap{This is the first line.} \hfill This is the centered line. \hspace*{\fill} \\
This is the next line.

In the second case, you need this:
Code:
This is the first line. \hfill This is the centered line. \hspace*{\fill} \\
This is the next line.

The outcomes from those will look something like this:
Code:
This is the first line....This is the centered line........|
This is the next line...............|
.............                      ...|
.............                      ...|
.............                      ...|
This is the first line....            ...This is the centered line.......|
This is the next line...............|
(the bar denotes where the right margin starts).

Most Helpful. Thank you!
 

Similar threads

  • · Replies 6 ·
Replies
6
Views
1K
  • · Replies 2 ·
Replies
2
Views
2K
  • · Replies 2 ·
Replies
2
Views
6K
  • · Replies 3 ·
Replies
3
Views
2K
Replies
10
Views
2K
  • · Replies 11 ·
Replies
11
Views
8K
  • · Replies 9 ·
Replies
9
Views
6K
  • · Replies 12 ·
Replies
12
Views
3K
  • · Replies 2 ·
Replies
2
Views
2K
  • · Replies 7 ·
Replies
7
Views
3K