For example,
Print["1\t55
33\t44"]
outputs
Why tab is not aligned? If tab is not aligned, why is it called tab? Is there a way to make tabs aligned?
Print
isn't really meant to do text-processor-like formatting. It most common use it to display intermediate results where people don't care much about pretty-printing. It produces an output cell where a tab character in a string is replaced with four spaces as is illustrated below.
Print["12345678\n1\t55\n33\t44"]
There are lots of ways to get the kind of formatting you want. Here is one of them, which requires only a little modification of your code.
CellPrint[TextCell["1\t55\n33\t44", "Text"]]
Print
output "a tab character in a string is replaced with four spaces"?
$\endgroup$
Commented
Apr 20, 2017 at 15:45
StandardForm
does not support tabs or newlines like regular text editor. It doesn't make sense to do so considering variety of 2D typesetting available there.
One can't even type \t
unless it is a beginning of the line.
tutorial / NewlinesAndTabsInStrings:
You should realize that even though it is possible to achieve some formatting of Wolfram Language output by creating strings which contain raw tabs and newlines, this is rarely a good idea. Typically a much better approach is to use the higher-level Wolfram Language formatting primitives [...
Column
etc]. These primitives will always yield consistent output, independent of such issues as the positions of tab settings on a particular device.
And Print
output is sent via $Output
which FormatType
is set to StandardForm
.
In practice this means that your input goes through Cell @ BoxData @ ToBoxes @ input
(roughly).
From what I've tried only TextForm
respects tabs. It is used in styles like Code / Program / Text
etc. Those cells contain TextData
or just plain string inside instead of BoxData
.
So the quick fix is:
Print @ TextCell["1\t55\n33\t44"]
or
Print @ RawBoxes @ Cell["1\t55\n33\t44"]
By the way, what documentation meant by "higher-level Wolfram Language formatting primitives" is something like:
Print @ Grid[ImportString["a\t55\n33\t44", "Table"], Alignment -> Left]