Ctrl + Enter not equal to \n in Mathematica

Hello,
To get a list as

So I coded as:

ToString[#] <> "month\n(here)") & /@ Range[12]

But the result is

So,

  1. Ctrl+Enter not equal \n ?
  2. How can I get a list as I wanted by codes not by Ctrl + Enter?

Thanks

You did get the list you wanted (except for the space which you should have added before month). Are you asking how to get a different presentation?

How are you intending to use the result? Maybe this would work for your use case

Labeled[ToString[#] <> " month", "(here)"] & /@ Range[12]

Hello,
I tried this,

(ToString[#] <> " month\n(here)") & /@ Range[12]

but the result is still the same.

Why Labeled will put the "(here)" below?

That’s just a trivial detail. My point is that your code succeeded. What else is it that you want?

What I expect is this effect

So put it in a grid. I’m so confused. How do you think what you’re showing is actually different than the result you got?

Read the documentation for Labeled. The default is Bottom. You can change it, e.g.

Labeled[ToString[#] <> " month", "(here)", Top] & /@ Range[12]

Yes. Thanks a lot.

There are obvious differences:

The first is entered by Ctrl+Enter. The second is entered by codes.
[1]: https://community.wolfram.com//c/portal/getImageAttachment?filename=37141.jpg&userId=2471588
[2]: https://community.wolfram.com//c/portal/getImageAttachment?filename=78872.jpg&userId=2471588

Sigh. Okay, I guess I read this the wrong way around. I thought you were trying to get newlines into your strings, and since that’s exactly what you did, I was confused. It seems that what you actually want is to create grid boxes programmatically.

Per the documentation, Ctrl+Enter is equivalent to Add Row (Insert > Table/Matrix > Add Row—Wolfram Documentation). So, the answer to your question

Ctrl+Enter not equal \n ?

is yes, Ctrl+Enter is not the same as \n.

As for your other question,

How can I get a list as I wanted by codes not by Ctrl + Enter?

Maybe use FullForm to see what expression you’ve actually created. Then go read about low-level box structures. It’s going to be much more complicated than “\n”.

I check the Fullform, but it is too complicated. It seems it is not easy to replace ‘\n’ by code.

I tested and this one works:

Grid[{{ToString[#] <> "month"}, {"(here)"}}] & /@ Range[12]

I tested and this one works:

Grid[{{ToString[#] <> "month"}, {"(here)"}}] & /@ Range[12]