I try to align horizontally 2 lines after 2 words, the first one not containing a subscript in text (see below with "WL") and the second one with a subscript (see GC_{sp}).
I used for this multiple attempts like \hphantom
or "\,
" but none of them is working. As you can see, there is a little shift between the 2 first left dash '-' symbols.
I want the first left dash '-
' symbol on the first line to be at the same place than the second line from an horizontal alignement point of view, i.e to be slightly shifted to the right.
Here the code snippet :
fisher_1.name = '\\parbox{9in}{ $ \\mathrm{WL\\hphantom{ } - Opt. Flat. No \gamma -} \\mathrm{FoM=47.05} $ }'
fisher_2.name = '\\parbox{9in}{ $ \\mathrm{GC_{sp} - Opt. Flat. No \gamma -} \\mathrm{FoM=60.49} $ }
If someone could have the trick to solve this issue...
EDIT1 :
the fisher_1.name
and fisher_2.name
are injected into the following structure from the library cosmicfish
:
fisher_list = fpa.CosmicFish_FisherAnalysis(
fisher_list=[
fisher_1,
fisher_2,
],
)
I recall that I would like the first '-' symbol to be at the same horizontal place from an horizontal alignement point of view, which implies a perfect alignement from the first dash '-' symbol up to the end of string ( 47.05
and 60.49
.
The last solution :
fisher_1.name = '\\parbox{9in}{$\\mathrm{WL}$\\hphantom{$\\mathrm{_{sp}}$} - FoM=47.05}'
fisher_2.name = '\\parbox{9in}{$\\mathrm{GC_{sp}}$ - FoM=60.49}'
doesn't work. I can't compensate the gap provocated by subscript _{sp}
EDIT 2: The only solution that works is basically :
fisher_1.name = 'WL - Opt. Flat. No gamma - FoM=47.05'
fisher_2.name = 'GCsp - Opt. Flat. No gamma - FoM=60.49'
With the other solutions suggested, I have compilation errors since I
define fisher_1.name
and fisher_2.name
in a Python
code with the library [cosmicfish][3]
.
If I want the greek symbol \gamma, this basic solution doesn't work anymore :
fisher_1.name = 'WL - Opt. Flat. No $\gamma$ - FoM=47.05'
fisher_2.name = 'GCsp - Opt. Flat. No $\gamma$ - FoM=60.49'
the same for :
fisher_1.name = 'WL - Opt. Flat. No $\\gamma$ - FoM=47.05'
fisher_2.name = 'GCsp - Opt. Flat. No $\\gamma$ - FoM=60.49'
I am disapointed that it doesn't work with all your solutions. I don't know what to do...
EDIT 3: I try to restart from the beginning with this example implemented in my Python code :
fisher_1.name = '\\parbox{\\widthof{$\\mathrm{GC_{sp}}$}}{$\\mathrm{WL}$} $\\mathrm{-\\ Opt.\\ Flat.\\ No\\ \\gamma - FoM=47.05} $'
fisher_2.name = '\\parbox{\\widthof{$\\mathrm{GC_{sp}}$}}{$\\mathrm{GC_{sp}}$} $\\mathrm{-\\ Opt.\\ Flat.\\ No\\ \\gamma - FoM=60.49} $'
At the execution of Python code, I get the following errors :
TITLE - name of file : \parbox{\widthof{$\mathrm{GC_{sp}}$}}{$\mathrm{WL}$} $\mathrm{-\ Opt.\ Flat.\ No\ \gamma - FoM=47.05} $
Traceback (most recent call last):
File "/opt/intel/oneapi/intelpython/latest/lib/python3.7/site-packages/matplotlib/texmanager.py", line 254, in _run_checked_subprocess
stderr=subprocess.STDOUT)
File "/opt/intel/oneapi/intelpython/latest/lib/python3.7/subprocess.py", line 411, in check_output
**kwargs).stdout
File "/opt/intel/oneapi/intelpython/latest/lib/python3.7/subprocess.py", line 512, in run
output=stdout, stderr=stderr)
subprocess.CalledProcessError: Command '['latex', '-interaction=nonstopmode', '--halt-on-error', '/Users/fab/.matplotlib/tex.cache/e8dd1b2348d85fb40145a12d56a0f625.tex']' returned non-zero exit status 1.
The above exception was the direct cause of the following exception:
Traceback (most recent call last):
File "main_synthesis.py", line 904, in <module>
plot_tri(fisher_plotter)
File "main_synthesis.py", line 206, in plot_tri
set_triplot_dimensions( self, num_col=len(params_temp), num_rows=len(params_temp), **kwargs )
File "main_synthesis.py", line 673, in set_triplot_dimensions
dimensions = self.get_dimensions_plot_obj()
File "cosmicfish-pyplots-py3/cosmicfish_pylib/fisher_plot.py", line 778, in get_dimensions_plot_obj
self.figure.canvas.draw()
File "/opt/intel/oneapi/intelpython/latest/lib/python3.7/site-packages/matplotlib/backends/backend_agg.py", line 406, in draw
self.figure.draw(self.renderer)
File "/opt/intel/oneapi/intelpython/latest/lib/python3.7/site-packages/matplotlib/artist.py", line 74, in draw_wrapper
result = draw(artist, renderer, *args, **kwargs)
File "/opt/intel/oneapi/intelpython/latest/lib/python3.7/site-packages/matplotlib/artist.py", line 51, in draw_wrapper
return draw(artist, renderer, *args, **kwargs)
File "/opt/intel/oneapi/intelpython/latest/lib/python3.7/site-packages/matplotlib/figure.py", line 2791, in draw
renderer, self, artists, self.suppressComposite)
File "/opt/intel/oneapi/intelpython/latest/lib/python3.7/site-packages/matplotlib/image.py", line 132, in _draw_list_compositing_images
a.draw(renderer)
File "/opt/intel/oneapi/intelpython/latest/lib/python3.7/site-packages/matplotlib/artist.py", line 51, in draw_wrapper
return draw(artist, renderer, *args, **kwargs)
File "/opt/intel/oneapi/intelpython/latest/lib/python3.7/site-packages/matplotlib/legend.py", line 609, in draw
bbox = self._legend_box.get_window_extent(renderer)
File "/opt/intel/oneapi/intelpython/latest/lib/python3.7/site-packages/matplotlib/offsetbox.py", line 352, in get_window_extent
w, h, xd, yd, offsets = self.get_extent_offsets(renderer)
File "/opt/intel/oneapi/intelpython/latest/lib/python3.7/site-packages/matplotlib/offsetbox.py", line 439, in get_extent_offsets
for c in self.get_visible_children()]
File "/opt/intel/oneapi/intelpython/latest/lib/python3.7/site-packages/matplotlib/offsetbox.py", line 439, in <listcomp>
for c in self.get_visible_children()]
File "/opt/intel/oneapi/intelpython/latest/lib/python3.7/site-packages/matplotlib/offsetbox.py", line 347, in get_extent
w, h, xd, yd, offsets = self.get_extent_offsets(renderer)
File "/opt/intel/oneapi/intelpython/latest/lib/python3.7/site-packages/matplotlib/offsetbox.py", line 475, in get_extent_offsets
for c in self.get_visible_children()]
File "/opt/intel/oneapi/intelpython/latest/lib/python3.7/site-packages/matplotlib/offsetbox.py", line 475, in <listcomp>
for c in self.get_visible_children()]
File "/opt/intel/oneapi/intelpython/latest/lib/python3.7/site-packages/matplotlib/offsetbox.py", line 347, in get_extent
w, h, xd, yd, offsets = self.get_extent_offsets(renderer)
File "/opt/intel/oneapi/intelpython/latest/lib/python3.7/site-packages/matplotlib/offsetbox.py", line 439, in get_extent_offsets
for c in self.get_visible_children()]
File "/opt/intel/oneapi/intelpython/latest/lib/python3.7/site-packages/matplotlib/offsetbox.py", line 439, in <listcomp>
for c in self.get_visible_children()]
File "/opt/intel/oneapi/intelpython/latest/lib/python3.7/site-packages/matplotlib/offsetbox.py", line 347, in get_extent
w, h, xd, yd, offsets = self.get_extent_offsets(renderer)
File "/opt/intel/oneapi/intelpython/latest/lib/python3.7/site-packages/matplotlib/offsetbox.py", line 475, in get_extent_offsets
for c in self.get_visible_children()]
File "/opt/intel/oneapi/intelpython/latest/lib/python3.7/site-packages/matplotlib/offsetbox.py", line 475, in <listcomp>
for c in self.get_visible_children()]
File "/opt/intel/oneapi/intelpython/latest/lib/python3.7/site-packages/matplotlib/offsetbox.py", line 823, in get_extent
bbox, info, yd = self._text._get_layout(renderer)
File "/opt/intel/oneapi/intelpython/latest/lib/python3.7/site-packages/matplotlib/text.py", line 315, in _get_layout
clean_line, self._fontproperties, ismath=ismath)
File "/opt/intel/oneapi/intelpython/latest/lib/python3.7/site-packages/matplotlib/backends/backend_agg.py", line 230, in get_text_width_height_descent
s, fontsize, renderer=self)
File "/opt/intel/oneapi/intelpython/latest/lib/python3.7/site-packages/matplotlib/texmanager.py", line 399, in get_text_width_height_descent
dvifile = self.make_dvi(tex, fontsize)
File "/opt/intel/oneapi/intelpython/latest/lib/python3.7/site-packages/matplotlib/texmanager.py", line 293, in make_dvi
texfile], tex, cwd=tmpdir)
File "/opt/intel/oneapi/intelpython/latest/lib/python3.7/site-packages/matplotlib/texmanager.py", line 267, in _run_checked_subprocess
exc=exc.output.decode('utf-8'))) from exc
RuntimeError: latex was not able to process the following string:
b'$\\\\mathrm{\\\\parbox{\\\\widthof{$\\\\mathrm{GC_{sp}}$}}{$\\\\mathrm{WL}$}\\\\ \\\\ $\\\\mathrm{-\\\\\\\\ Opt.\\\\\\\\ Flat.\\\\\\\\ No\\\\\\\\ \\\\gamma\\\\ -\\\\ FoM=47.05}\\\\ $}$'
Here is the full report generated by latex:
This is pdfTeX, Version 3.14159265-2.6-1.40.21 (TeX Live 2020/MacPorts 2020.54632_1) (preloaded format=latex)
restricted \write18 enabled.
entering extended mode
(/Users/fab/.matplotlib/tex.cache/e8dd1b2348d85fb40145a12d56a0f625.tex
LaTeX2e <2020-02-02> patch level 5
L3 programming layer <2020-03-06>
(/opt/local/share/texmf-texlive/tex/latex/base/article.cls
Document Class: article 2019/12/20 v1.4l Standard LaTeX document class
(/opt/local/share/texmf-texlive/tex/latex/base/size10.clo))
(/opt/local/share/texmf-texlive/tex/latex/type1cm/type1cm.sty)
(/opt/local/share/texmf-texlive/tex/latex/cm-super/type1ec.sty
(/opt/local/share/texmf-texlive/tex/latex/base/t1cmr.fd))
(/opt/local/share/texmf-texlive/tex/latex/base/inputenc.sty)
(/opt/local/share/texmf-texlive/tex/latex/geometry/geometry.sty
(/opt/local/share/texmf-texlive/tex/latex/graphics/keyval.sty)
(/opt/local/share/texmf-texlive/tex/generic/iftex/ifvtex.sty
(/opt/local/share/texmf-texlive/tex/generic/iftex/iftex.sty)))
(/opt/local/share/texmf-texlive/tex/latex/base/textcomp.sty)
(/opt/local/share/texmf-texlive/tex/latex/l3backend/l3backend-dvips.def)
No file e8dd1b2348d85fb40145a12d56a0f625.aux.
*geometry* driver: auto-detecting
*geometry* detected driver: dvips
! Undefined control sequence.
<argument> \widthof
{$\mathrm {GC_{sp}}$}
l.19 ....\\ Flat.\\ No\\ \gamma\ -\ FoM=47.05}\ $}
$}
No pages of output.
Transcript written on e8dd1b2348d85fb40145a12d56a0f625.log.
EDIT 4: A partial solution is done :
fisher_1.name = '\\parbox{9in}{\\rlap{$\\mathrm{WL}$}\\hphantom{$\\mathrm{GC_{sp}}$} - FoM=47.05}'
fisher_2.name = '\\parbox{9in}{$\\mathrm{GC_{sp}}$ - FoM=60.49}'
As you can see, and for a reason I ignore, the "WL" string is pushed to the top, I don't why. The font for strings "FoM=47.05" and "FoM=60.49" is also weird.
So, we are near to a solution since the alignement regarding first dash '-
' is respected.
SOLUTION : has been found by Heiko Theiße
:
these 2 lines did the trick :
fisher_1.name = '\\rlap{$\\mathrm{WL}$\\hphantom{\\mathrm{GC_{sp}}} - FoM=47.05'
fisher_2.name = 'GC_{sp} - FoM=60.49'
Regards
tabular
format?tabular
in my case ? I injectfisher_1.name
andfisher_2.name
after in a legend.\documentclass{book} \usepackage{tabularx} \begin{document} \begin{tabularx}{\textwidth}{lcp{5cm}} $ \mathrm{WL}$ &$-$ &$\mathrm{Opt. Flat. No \gamma - FoM=47.05} $\\ $ \mathrm{GC_{sp}}$ &$-$ &$\mathrm{Opt. Flat. No \gamma - FoM=60.49}$ \end{tabularx} \end{document}
tabto
package. Please see the manual.