pytexutils.figures.tabular_image

 1from ..tables.table import table
 2import numpy as np
 3
 4def tabular_image(images_full_path : np.ndarray, caption : str = "table_caption", label : str = "table_label", preamble : bool = False) -> str:
 5    '''
 6        Produces LaTeX code to display a table of images.
 7
 8        Parameters:  
 9        ----------- 
10        - images_full_path
11            2D ndarry of strings, path of the image in the LaTeX project
12        - caption : str  
13            string for the caption of LaTeX table (default: "table_caption")  
14        - label : str  
15            string for the label of LaTeX table (default: "table_label")  
16        - preamble : bool  
17            If True the function will return a full LaTeX document, if False the function will return only the table (default: False)
18
19        Returns:  
20        --------  
21        - p : str  
22            LaTeX code to display a table of images.
23        
24        Usage:
25        ------
26
27        ```python
28
29        import numpy as np
30
31        images = np.array(  
32            [["fig1.png", "fig2.png"],["fig1.png", "fig2.png"]]  
33        )  
34    
35        latex_table = tabular_image(images, caption='My image 1', label='img1', preamble=True)  
36        ```
37
38        Output:
39        -------
40
41        ```latex
42        \\documentclass[11pt]{article}
43        \\usepackage{booktabs}
44        \\usepackage{graphicx}
45
46        \\begin{document}
47
48        \\begin{table}[!ht]
49                \\centering
50                \\caption{My image 1}\\label{tab:img1}
51                \\resizebox{\\columnwidth}{!}{
52                \begin{tabular}{cc}
53                        \\toprule
54                            \\includegraphics[width=\\columnwidth]{fig1.png}     &     \\includegraphics[width=\\columnwidth]{fig2.png}     \\\\
55                            \\includegraphics[width=\\columnwidth]{fig1.png}     &     \\includegraphics[width=\\columnwidth]{fig2.png}     \\\\
56                        \\bottomrule
57                \\end{tabular}}
58        \\end{table}
59        ```
60    '''
61
62    if len(images_full_path.shape) != 2:
63        raise Exception("Error Message: images_full_path must be a 2D array")
64
65    images_full_path = images_full_path.astype(object)
66
67    for i in range(images_full_path.shape[0]):
68        for j in range(images_full_path.shape[1]):
69            images_full_path[i,j] = "\\includegraphics[width=\\columnwidth]{"+str(images_full_path[i,j])+"}"
70
71    p = table(None, images_full_path, caption=caption, label=label, preamble=preamble)
72
73    return p
def tabular_image( images_full_path: numpy.ndarray, caption: str = 'table_caption', label: str = 'table_label', preamble: bool = False) -> str:
 5def tabular_image(images_full_path : np.ndarray, caption : str = "table_caption", label : str = "table_label", preamble : bool = False) -> str:
 6    '''
 7        Produces LaTeX code to display a table of images.
 8
 9        Parameters:  
10        ----------- 
11        - images_full_path
12            2D ndarry of strings, path of the image in the LaTeX project
13        - caption : str  
14            string for the caption of LaTeX table (default: "table_caption")  
15        - label : str  
16            string for the label of LaTeX table (default: "table_label")  
17        - preamble : bool  
18            If True the function will return a full LaTeX document, if False the function will return only the table (default: False)
19
20        Returns:  
21        --------  
22        - p : str  
23            LaTeX code to display a table of images.
24        
25        Usage:
26        ------
27
28        ```python
29
30        import numpy as np
31
32        images = np.array(  
33            [["fig1.png", "fig2.png"],["fig1.png", "fig2.png"]]  
34        )  
35    
36        latex_table = tabular_image(images, caption='My image 1', label='img1', preamble=True)  
37        ```
38
39        Output:
40        -------
41
42        ```latex
43        \\documentclass[11pt]{article}
44        \\usepackage{booktabs}
45        \\usepackage{graphicx}
46
47        \\begin{document}
48
49        \\begin{table}[!ht]
50                \\centering
51                \\caption{My image 1}\\label{tab:img1}
52                \\resizebox{\\columnwidth}{!}{
53                \begin{tabular}{cc}
54                        \\toprule
55                            \\includegraphics[width=\\columnwidth]{fig1.png}     &     \\includegraphics[width=\\columnwidth]{fig2.png}     \\\\
56                            \\includegraphics[width=\\columnwidth]{fig1.png}     &     \\includegraphics[width=\\columnwidth]{fig2.png}     \\\\
57                        \\bottomrule
58                \\end{tabular}}
59        \\end{table}
60        ```
61    '''
62
63    if len(images_full_path.shape) != 2:
64        raise Exception("Error Message: images_full_path must be a 2D array")
65
66    images_full_path = images_full_path.astype(object)
67
68    for i in range(images_full_path.shape[0]):
69        for j in range(images_full_path.shape[1]):
70            images_full_path[i,j] = "\\includegraphics[width=\\columnwidth]{"+str(images_full_path[i,j])+"}"
71
72    p = table(None, images_full_path, caption=caption, label=label, preamble=preamble)
73
74    return p

Produces LaTeX code to display a table of images.

Parameters:

  • images_full_path 2D ndarry of strings, path of the image in the LaTeX project
  • caption : str
    string for the caption of LaTeX table (default: "table_caption")
  • label : str
    string for the label of LaTeX table (default: "table_label")
  • preamble : bool
    If True the function will return a full LaTeX document, if False the function will return only the table (default: False)

Returns:

  • p : str
    LaTeX code to display a table of images.

Usage:

import numpy as np

images = np.array(  
    [["fig1.png", "fig2.png"],["fig1.png", "fig2.png"]]  
)  

latex_table = tabular_image(images, caption='My image 1', label='img1', preamble=True)  

Output:

\documentclass[11pt]{article}
\usepackage{booktabs}
\usepackage{graphicx}

\begin{document}

\begin{table}[!ht]
        \centering
        \caption{My image 1}\label{tab:img1}
        \resizebox{\columnwidth}{!}{
        egin{tabular}{cc}
                \toprule
                    \includegraphics[width=\columnwidth]{fig1.png}     &     \includegraphics[width=\columnwidth]{fig2.png}     \\
                    \includegraphics[width=\columnwidth]{fig1.png}     &     \includegraphics[width=\columnwidth]{fig2.png}     \\
                \bottomrule
        \end{tabular}}
\end{table}