Message Boards Message Boards

0
|
1908 Views
|
14 Replies
|
0 Total Likes
View groups...
Share
Share this post:

Ctrl + Enter not equal to \n in Mathematica

Posted 1 year ago

Hello, To get a list as enter image description here

So I coded as:

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

But the result is enter image description here

So,

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

Thanks

POSTED BY: Zhenyu Zeng
14 Replies

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

Labeled[ToString[#] <> " month", "(here)", Top] & /@ Range[12]
POSTED BY: Rohit Namjoshi
Posted 1 year ago

Yes. Thanks a lot.

POSTED BY: Zhenyu Zeng
Posted 1 year ago

I tested and this one works:

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

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

Labeled[ToString[#] <> " month", "(here)"] & /@ Range[12]
POSTED BY: Rohit Namjoshi
Posted 1 year ago

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

POSTED BY: Zhenyu Zeng
Posted 1 year ago

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?

POSTED BY: Eric Rimbey
Posted 1 year ago

Hello, I tried this,

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

but the result is still the same.

POSTED BY: Zhenyu Zeng
Posted 1 year ago

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

POSTED BY: Eric Rimbey
Posted 1 year ago

What I expect is this effect enter image description here

POSTED BY: Zhenyu Zeng
Posted 1 year ago

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?

POSTED BY: Eric Rimbey
Posted 1 year ago

There are obvious differences:enter image description hereenter image description here

The first is entered by Ctrl+Enter. The second is entered by codes.

POSTED BY: Zhenyu Zeng
Posted 1 year ago

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 (http://reference.wolfram.com/language/ref/menuitem/AddRow.html). 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".

POSTED BY: Eric Rimbey
Posted 1 year ago

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

POSTED BY: Zhenyu Zeng
Posted 1 year ago

I tested and this one works:

Grid[{{ToString[#] <> "month"}, {"(here)"}}] & /@ Range[12]
POSTED BY: Zhenyu Zeng
Reply to this discussion
Community posts can be styled and formatted using the Markdown syntax.
Reply Preview
Attachments
Remove
or Discard

Group Abstract Group Abstract