How many spaces are there in tab?

I want to implement a text drawing function. But I am not sure how \t works, which means I don't know how many spaces I should print for \t.

I have come up with the following algorithm:

a) Each \t represents at most NUMBER_OF_SPACES_FOR_TAB spaces. b) If \t appears in the last line at a corresponding position, \t for this line should be aligned to the \t of last line.

Example:

printf("a\t\tb\n");
printf("\t\tc\n");

Should print:

a11112222b
34444c

Where:

1.Number i represents the spaces of \t at position i

2.NUMBER_OF_SPACES_FOR_TAB == 4

Does anyone know the standard algorithm? Thanks in advance.

asked Oct 26, 2012 at 21:28

Chao ZhangChao Zhang

1,4162 gold badges14 silver badges25 bronze badges

5

A tab character should advance to the next tab stop. Historically tab stops were every 8th character, although smaller values are in common use today and most editors can be configured.

I would expect your output to look like the following:

123456789
a       b
        c

The algorithm is to start a column count at zero, then increment it for each character output. When you get to a tab, output n-(c%n) spaces where c is the column number (zero based) and n is the tab spacing.

answered Oct 26, 2012 at 21:32

Mark RansomMark Ransom

290k40 gold badges384 silver badges607 bronze badges

16

Imagine a ruler with tab stops every 8 spaces. A tab character will align text to the next tab stop.

                                0       8       16      24      32      40
                                |.......|.......|.......|.......|.......|
printf("\tbar\n");              \t      bar
printf("foo\tbar\n");           foo\t   bar
printf("longerfoo\tbar");       longerfoo\t     bar

To calculate where the next tab stop is, take the current column.

nextTabStop = (column + 8) / 8 * 8

The / 8 * 8 part effectively truncates the result to the nearest multiple of 8. For example, if you're at column 11, then (11 + 8) is 19 and 19 / 8 is 2, and 2 * 8 is 16. So the next tab stop from column 11 is at column 16.

In a text editor you may configure tab stops to smaller intervals, like every 4 spaces. If you're simulating what tabs look like at a terminal you should stick with 8 spaces per tab.

answered Oct 26, 2012 at 21:33

John KugelmanJohn Kugelman

336k66 gold badges509 silver badges559 bronze badges

3

A Tab character shifts over to the next tab stop. By default, there is one every 8 spaces. But in most shells you can easily edit it to be whatever number of spaces you want (profile preferences in linux, set tabstop in vim).

answered Oct 26, 2012 at 21:35

WhyrusleepingWhyrusleeping

8392 gold badges8 silver badges20 bronze badges

This doesn't necessarily apply to the article, but In the old days of typewriters and fixed-width fonts, a tab was 5 spaces, because five characters was half an inch. That's pretty irrelevant now, though.

How many spaces are there in tab?

Most people do not know how to use tabs and spaces correctly. Some people will use the space key to align text when formatting their document in Word, which is wrong. You should know that different characters may vary in the number of spaces they take up. Therefore you cannot use the space key to align your text correctly.

The advantage of using the tab key to align your text is that you can realign your text by moving or changing the tab stops. Therefore you can easily make modifications to your text. Most people wonder how many spaces get displayed when you press the tab key. Here is everything to know about the tab and space key.

How Many Spaces Is A Tab?

The number of spaces of one press of the tab key depends on the fonts used. Generally, a tab is about four to five spaces. However, to have an accurate result, ensure that the font you use equally sizes each character. If you are using the courier fonts, one tab will be equal to five spaces.

On the other hand, if you are using Aerial font, one tab will equal eleven spaces. The more you increase the font size, the fewer spaces per tab you will get.

Types Of Tab Stop In Word

When editing your document in Word, you can align the text using the tab key. A tab stop is where your cursor will move once you press the tab key on your keyboard. Apart from indenting paragraphs, one can also use tabs to create single and multi-column lists. You will find five different kinds of tab stops in your Word. These tab stops include.

  • The left tab stop: The left tab stop is the most common tab stop used in Word. The role of the left tab stop s to place the left aligned text to the right of the tab stop.
  • The right tab stop: Another tab stop you can find in Microsoft Word is the right tabs stop. The right tab is the direct opposite of the left tab. It ensures that the right-aligned texts get placed to the left of the tab stop.
  • The center tab stop: Apart from the right and left tab stops, there is also the center tab stop. If you want to center your text on the tab stop, you will use the center tab stop.
  • The decimal tab stop: The other type of tab stop is the decimal tab stop. The work of the decimal tab stop is to align text based on the first decimal placed on the tab stop.
  • The bar tab stop: The last type of tab stops is the bar tab. People create vertical lines at the tab stop using this type of tab stop. However, technically, the bar tab is not a tab stop. People use it for formatting multi-column lists.

Steps To Changing The Default Tab Of Microsoft Word

Microsoft Word will automatically move your cursor half an inch to the right by pressing the Tab key on your keyboard. You can change this setting and adjust the length of your default left tab stop. Moreover, you can do this without having to create a new tab.

If you want to change the length of your default left tab stop, you should follow the following steps. It would be best to note that these steps will only affect your current document. You will have to modify your ‘’normal.dotm template’’ to change all your future documents. The following are the steps to changing the default tab in your Microsoft word.

  • The first thing to do is to open the document you want to make changes to. You will then go to the ribbon and select the ‘’HOME’’ option.
  • On the paragraph section next to the font section, you will click on its dialogue box launcher. Once you click on it, a paragraph dialogue box will get displayed.
  • On the paragraph dialogue box, click on the ‘’TAB’’ button at the bottom of the box. Clicking on that button, Word will take you to a Tab dialogue box. There you will see tab stop positions, default tab stops, alignment, and leaders options. 
  • On the Tab dialogue box, you can change the length of your default tab stop on the ‘’default tab stop’’ option box. You can adjust the length using the increment arrows or typing the length you want directly on the box. You can also change the alignment of your default tab stops to either right, center, decimal, or bar. You will then click on the ok button to save the changes.

Creating A Tab On Word’s Ruler

Before you create a tab on your Word’s ruler, you should ensure that you enable formatting marks and rulers. The formatting marks will help you see what is happening in your document. On the other hand, the ruler will help you quickly add, move and remove tab stops. The following are some of the steps you can follow to create a tab on Word’s ruler.

  • If your Word does not display the ruler, ensure you follow these simple steps to make it visible. However, if your ruler is visible, you can skip these steps.
  • Go to the ribbon at the top of your Word and select the ‘’VIEW’’ tab. On the View tab, go to the show box and click on the ruler.
  • You will then select your entire document or the part on your document that you want to apply the tab.
  • Once your ruler is visible, you will click on the tab selector button to change the tap stop to the type you want.
  • The next thing is to click on your ruler where you want to place the tab stop. Once you do that, the tab symbol will appear on the ruler. 

Indenting Text Using The Tab Key

Most people will indent only the first line of a paragraph. The purpose of doing this is to distinguish one paragraph from another visually. However, some people can also use hanging indents to indent the whole paragraph except the first line.

The mistake that most people make is to indent text using the space key. Using the space key will make your text not have a uniform look. The best way to indent text is by using the tab key since it ensures your text alignment is neat. The following are the steps to indent texts using the tab key.

  • The first thing you will do is place the insertion point at the start of your paragraph.
  • Once that is in place, you will press the tab key on the ruler. You will observe that the first-line indent marker will move half an inch to the right-tab stop.
  • Once you finish the process, the first line of your paragraph will get indented.

Indent Markers

The role of an indent marker is to allow you to indent paragraphs to the location you want. You can find the indent markers on the left side of the horizontal ruler. Indent makers provide the following indenting options.

  • First-line indent marker: used to adjust the first-line indent
  • Hanging indent marker: used to adjust the hanging indent
  • Left indent marker: used to adjust both the first-line and hanging indent at once.

Line And Paragraph Spacing

Line spacing is the spaces between the lines in a paragraph. You can customize the line spacing to either single space or double space. The single space has one line high, while the double space has two lines high.

To format the line spacing, you will first select the text you and to format the click on the line and paragraph spacing command. You will then select the desired line spacing, and the line spacing will change on your document.

Paragraph spacing creates additional spaces before every paragraph, thus separating them a bit more. Doing this will make it easier for the reader to read the document. To format the paragraph spacing, you will first select the paragraph you want to format.

You will then go to the line and paragraph spacing command. You will click either add space before a paragraph or remove space after paragraph on the line and paragraph spacing command. Once you do this, your document’s paragraph spacing will change.

How Do You Indent Without The Tab Key?

You can still indent your paragraph even without using the tab key. You will go to the Format menu and select ‘’Paragraph’’. You will then click the indent and spacing tab and select the First Line from the special control’s drop-down list. You will use the By control’s drop-down list to specify the indention size and the click ok.

Tabs Or Spaces?

The choice of using tab or space key lies on what activity you want to do in Microsoft Word and the user. Both tab and space keys are essential and can perform different activities. You should ensure you use both keys correctly.

Conclusion

The tab key is essential when you want to indent texts. It ensures that your text is neat after indenting. The space key is vital when typing as it spaces words in your text. The number of spaces in one tab varies depending on the fonts you use. However, the standard number of spaces in one tab is around five spaces.

Similar Posts:

Is a tab 4 or 8 spaces?

Four spaces should be used as the unit of indentation. The exact construction of the indentation (spaces vs. tabs) is unspecified. Tabs must be set exactly every 8 spaces (not 4).

Is tab always 4 spaces?

Sets the distance in spaces between tab stops. The default is four spaces.

Is tab the same as 2 spaces?

Answer. In most code editors, tabs are not the same as 2 spaces or 4 spaces by default. A tab is stored differently than spaces in the code. Tabs can be seen as a big “jump” in the text, while spaces are always 1 space each.