2

I am looking for help in aligning text within HTML tables inside of DiagrammeR nodes.

In this working example:

library(DiagrammeR)

grViz(
  "digraph consort_diagram {
      graph[splines = ortho]
      node [fontname = Helvetica, shape = box]
        mylabel [label = < 
          <table border='0' cellborder='0' cellspacing='0'>
          <tr>
            <td align = 'right'>12</td>
            <td align = 'left'>This is some text that is very long indeed indeed.</td>
          </tr>
          <tr>
            <td align = 'right'>5</td>
            <td align = 'left'>This is short text.</td>
          </tr>
          </table>
        >]
  }"
)

I am able to get two lines of text within a node box. This works as intended, with the first column right aligned, and second column left aligned: first image I run into problems when I include <br/> in the long lines. I am hoping to wrap text inside the boxes, and using strwrap with <br/> seemed like a possible solution.

Unfortunately, when I add the line break, such as here:

<td align = 'left'>This is some text that is very<br/>long indeed indeed.</td>

The alignment assumes the default style for DiagrammeR nodes, with centering: second image Ideally, I want to keep the left alignment of the second column, and if possible, make the vertical text alignment "top".

I am very open to alternative approaches, am happy to edit the question to provide more information, and appreciate the assistance greatly.

Ben
  • 28,684
  • 5
  • 23
  • 45
  • Hi! You can add style="text-align: left;" to your table for the text alignment. I would suggest instead of using the line break, defining a width for the table and a overflow property for it so it "breaks" automatically. – Ale Plo Oct 17 '20 at 22:08
  • @AlePlo Many thanks for the response, it is much appreciated. I did try adding `style` to the table and defining width, but while this works generally in my HTML tables, this did not seem to work when produced with `grViz` and `DiagrammeR`. I am also looking into just creating additional rows to the table and avoiding line breaks. Again, I very much appreciate your help. – Ben Oct 18 '20 at 14:29

0 Answers0