5
$\begingroup$

I'm trying to make continuous blocks of cells so that their background colors are the same, but without breaks of white space between them.

E.g.

enter image description here

After some recent digging, I found the option "Show Expression", which converts the cell to its explicit contents that Mathematica can interpret. For example, the third cell in the image can be created by writing

CellPrint[
    Cell["Can we make all",
         "Text",
         Background->RGBColor[0.87,0.94,1]
        ]
 ]

Showing the expression gives more information than I need, which I've omitted in this example. (Things like CellChangeTimes and expression for symbols like the apostrophes. There was also an option specifying the grouping.)

I'm wondering if there's a simple way to use this code to my advantage so I can format the cells so that the line break between stays the same color.

I realize that with text, I can just start a new paragraph by hitting Return a few times, but I'm trying to include examples of Mathematica code for plots and the like.

Edit: Using Stephen's suggestion from the comments, I'm running into some minor issues with my graphics, as in the pic below. A quick fix is to add Background->White where appropriate. The top cell shows what happens when this option is left out, and the bottom shows when it's applied to GraphicsRow. Another has to be added elsewhere (in my case, to Pane) to remove the blue frame.

enter image description here

$\endgroup$
6
  • 1
    $\begingroup$ You can use the CellMargins option of Cell to do what you want. $\endgroup$ May 25, 2015 at 19:42
  • $\begingroup$ I'm not sure this answers my question... Could you perhaps give an example of the proper syntax? The documentation center doesn't quite address what I want to accomplish. $\endgroup$
    – user170231
    May 25, 2015 at 21:15
  • $\begingroup$ Cell["Hello", "Text", CellMargins->{{66, 10}, {0, 0}}, Background->RGBColor[0.87, 0.94, 1]] followed by Cell["World", "Text", CellMargins->{{66, 10}, {0, 0}}, Background->RGBColor[0.87, 0.94, 1]]. $\endgroup$ May 25, 2015 at 22:13
  • 1
    $\begingroup$ I achieved this result by typing Hello and World in 2 successive text cells, then I selected the cell brackets, opened the option inspector, then I altered the values displayed at Cell Options / Display Options / CellMargins. $\endgroup$ May 25, 2015 at 22:17
  • $\begingroup$ Ah perfect, thanks! I feel like there should be a more accessible way to accomplish this, perhaps through the Cell or Format toolbar. Fortunately, I only have to do this for a few cells (this time). $\endgroup$
    – user170231
    May 26, 2015 at 0:50

1 Answer 1

4
$\begingroup$

Here's one possible way of doing this.

Type some text into 2 successive text cells, then select the cell brackets, open the option inspector (Format / Option Inspector ...) and alter the values displayed at Cell Options / Display Options / CellMargins.

For instance, if the 2 text items are "Hello" and "World", then the resulting Cell expressions might be (Cell / Show Expression)

Cell["Hello", "Text", CellMargins->{{66, 10}, {0, 0}},
  Background->RGBColor[0.87, 0.94, 1]]

and

Cell["World", "Text", CellMargins->{{66, 10}, {0, 0}}, 
  Background->RGBColor[0.87, 0.94, 1]]

where I have set the top and bottom margins both to be 0.

$\endgroup$

Your Answer

By clicking “Post Your Answer”, you agree to our terms of service and acknowledge that you have read and understand our privacy policy and code of conduct.

Not the answer you're looking for? Browse other questions tagged or ask your own question.