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

Discussion Overview

The discussion revolves around formatting text in LaTeX, specifically addressing the issue of unwanted spacing when using environments like 'center'. Participants explore various methods to control spacing and align text on the same line or on separate lines.

Discussion Character

  • Technical explanation
  • Debate/contested
  • Mathematical reasoning

Main Points Raised

  • One participant expresses a desire to eliminate the default spacing that appears when using the 'center' environment in LaTeX, seeking a way to control the amount of space left.
  • Another participant suggests using the \hspace command to manually adjust spacing, although they describe this method as somewhat crude and question if a two-column layout is intended.
  • A later reply reiterates the initial concern and proposes using plain TeX spacing commands instead of the 'center' environment, presenting multiple formatting options depending on whether the centered line should be on the same line or a separate line.
  • Different formatting methods are outlined, including the use of \hfill and \rlap to achieve desired text alignment, with examples of how these commands would visually appear in the output.

Areas of Agreement / Disagreement

Participants do not reach a consensus on the best approach, as multiple methods are proposed and the specific formatting needs remain unclear. There is no agreement on whether the centered line should be on the same line or a separate line, leading to various interpretations of the problem.

Contextual Notes

The discussion highlights limitations in clarity regarding the desired outcome of the text formatting, as well as the dependence on specific LaTeX commands and environments. The effectiveness of proposed solutions may vary based on individual requirements.

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