Skip to main content
Add method for opos = {0,0}
Source Link
Carl Woll
  • 131.7k
  • 6
  • 246
  • 359

I don't think you're using Inset properly. Look at the documentation:

?Inset

(*
Inset[obj] represents an object obj inset in a graphic. 
Inset[obj,pos] specifies that the inset should be placed at position pos in the graphic. 
Inset[obj,pos,opos] aligns the inset so that position opos in the object lies at position pos in the enclosing graphic. 
Inset[obj,pos,opos,size] specifies the size of the inset in the coordinate system of the enclosing graphic. 
Inset[obj,pos,opos,size,dirs] specifies that the axes of the inset should be oriented in directions dirs.  >>
*)

Notice that the second usage statement says that the inset is placed at position pos in the graphic. Yet you are using different values for pos for even and odd lines. Secondly, when using a Text object in an inset, using {0, 0} for the opos value means that the center of the Text object is placed at pos. You should instead use {-1, 0} for the opos value so that the left end of the Text object starts at pos. So, using the same pos value for each row, and {-1, 0} for the opos value would produce left-aligned output. For example:

nmax=10;
Graphics[
    Table[
        With[{v=StringJoin@@Table["a",Mod[n,2,1]*10]},
            Inset[Text[v], Offset[{0, 0}, {0, n/nmax}], {-1,0}]
        ],
        {n,1,nmax}
    ]
]

enter image description here

Addendum

If you must use {0, 0} for $\operatorname{opos}$, then to get the raster size right you should include an explicit FontSize setting:

Graphics[
    Table[
        With[{v = StringJoin @@ Table["a",Mod[n,2,1]*10]},
            Inset[
                Text[Style[v,16]],
                Offset[
                    Rasterize[Text[Style[v,16]],"RasterSize"]/2+{3,0},
                    {0,n/nmax}
                ],
                {0,0}
            ]
        ],
        {n,1,nmax}
    ]
]

enter image description here

I don't think you're using Inset properly. Look at the documentation:

?Inset

(*
Inset[obj] represents an object obj inset in a graphic. 
Inset[obj,pos] specifies that the inset should be placed at position pos in the graphic. 
Inset[obj,pos,opos] aligns the inset so that position opos in the object lies at position pos in the enclosing graphic. 
Inset[obj,pos,opos,size] specifies the size of the inset in the coordinate system of the enclosing graphic. 
Inset[obj,pos,opos,size,dirs] specifies that the axes of the inset should be oriented in directions dirs.  >>
*)

Notice that the second usage statement says that the inset is placed at position pos in the graphic. Yet you are using different values for pos for even and odd lines. Secondly, when using a Text object in an inset, using {0, 0} for the opos value means that the center of the Text object is placed at pos. You should instead use {-1, 0} for the opos value so that the left end of the Text object starts at pos. So, using the same pos value for each row, and {-1, 0} for the opos value would produce left-aligned output. For example:

nmax=10;
Graphics[
    Table[
        With[{v=StringJoin@@Table["a",Mod[n,2,1]*10]},
            Inset[Text[v], Offset[{0, 0}, {0, n/nmax}], {-1,0}]
        ],
        {n,1,nmax}
    ]
]

enter image description here

I don't think you're using Inset properly. Look at the documentation:

?Inset

(*
Inset[obj] represents an object obj inset in a graphic. 
Inset[obj,pos] specifies that the inset should be placed at position pos in the graphic. 
Inset[obj,pos,opos] aligns the inset so that position opos in the object lies at position pos in the enclosing graphic. 
Inset[obj,pos,opos,size] specifies the size of the inset in the coordinate system of the enclosing graphic. 
Inset[obj,pos,opos,size,dirs] specifies that the axes of the inset should be oriented in directions dirs.  >>
*)

Notice that the second usage statement says that the inset is placed at position pos in the graphic. Yet you are using different values for pos for even and odd lines. Secondly, when using a Text object in an inset, using {0, 0} for the opos value means that the center of the Text object is placed at pos. You should instead use {-1, 0} for the opos value so that the left end of the Text object starts at pos. So, using the same pos value for each row, and {-1, 0} for the opos value would produce left-aligned output. For example:

nmax=10;
Graphics[
    Table[
        With[{v=StringJoin@@Table["a",Mod[n,2,1]*10]},
            Inset[Text[v], Offset[{0, 0}, {0, n/nmax}], {-1,0}]
        ],
        {n,1,nmax}
    ]
]

enter image description here

Addendum

If you must use {0, 0} for $\operatorname{opos}$, then to get the raster size right you should include an explicit FontSize setting:

Graphics[
    Table[
        With[{v = StringJoin @@ Table["a",Mod[n,2,1]*10]},
            Inset[
                Text[Style[v,16]],
                Offset[
                    Rasterize[Text[Style[v,16]],"RasterSize"]/2+{3,0},
                    {0,n/nmax}
                ],
                {0,0}
            ]
        ],
        {n,1,nmax}
    ]
]

enter image description here

Source Link
Carl Woll
  • 131.7k
  • 6
  • 246
  • 359

I don't think you're using Inset properly. Look at the documentation:

?Inset

(*
Inset[obj] represents an object obj inset in a graphic. 
Inset[obj,pos] specifies that the inset should be placed at position pos in the graphic. 
Inset[obj,pos,opos] aligns the inset so that position opos in the object lies at position pos in the enclosing graphic. 
Inset[obj,pos,opos,size] specifies the size of the inset in the coordinate system of the enclosing graphic. 
Inset[obj,pos,opos,size,dirs] specifies that the axes of the inset should be oriented in directions dirs.  >>
*)

Notice that the second usage statement says that the inset is placed at position pos in the graphic. Yet you are using different values for pos for even and odd lines. Secondly, when using a Text object in an inset, using {0, 0} for the opos value means that the center of the Text object is placed at pos. You should instead use {-1, 0} for the opos value so that the left end of the Text object starts at pos. So, using the same pos value for each row, and {-1, 0} for the opos value would produce left-aligned output. For example:

nmax=10;
Graphics[
    Table[
        With[{v=StringJoin@@Table["a",Mod[n,2,1]*10]},
            Inset[Text[v], Offset[{0, 0}, {0, n/nmax}], {-1,0}]
        ],
        {n,1,nmax}
    ]
]

enter image description here