3

Hello the following tikz picture works when by itself but when I put it into a figure like in the following code this error comes up: Package pgfplots Error: ! Package pgfplots Error: Could not read table file '" x y z 10 -1 -1 10 1 -1 1 0 1 1 10 -1 1 10 -1 -1 "' in 'search path=.'

Code

\documentclass[test]{report}
\usepackage[T1]{fontenc}
\usepackage[latin9]{luainputenc}
\setcounter{secnumdepth}{3}
\setcounter{tocdepth}{3}

\makeatletter
\usepackage{bohr}
\usepackage{carbohydrates}
\usepackage{chemfig}
\usepackage{tikz}
 \usepackage{pgfplots}

\pgfplotsset{compat=1.12}

\@ifundefined{showcaptionsetup}{}{%
 \PassOptionsToPackage{caption=false}{subfig}}
\usepackage{subfig}
\makeatother

\usepackage{babel}
\begin{document}
\begin{figure}
\subfloat[]{\begin{tikzpicture}[     
declare function={squarex(\t) =         
    (\t < 0.25) ? 1 : (             
        (\t < 0.5) ? (1 - (\t-0.25) * 8) : (                 
            (\t < 0.75) ? -1 : (-1 + (\t - 0.75) * 8)         
    )     
;},     
declare function={squarey(\t) =         
    (\t < 0.25) ? (-1 + \t*8) : (             
        (\t < 0.5) ? 1 : (                 
            (\t < 0.75) ? (1 - (\t - 0.5) * 8) : -1         
    )     
;} 
] 
\begin{axis}[    
axis equal image,      
z buffer=sort,
hide axis,      
domain=0:1, y domain = 0:10, samples y = 25,     
ylabel =y, xlabel=x,     clip=false 
]
\addplot3 [     
z buffer=none, domain=0:330, samples y=1,     
ultra thick, black, -latex] (     
-0.5,     
{sin(x)*1.5},     {cos(x)*1.5} 
);
\addplot3 [surf, shader=flat, fill=black!10, draw=black] (     
y,     
{squarex(x) * cos(y*9) - squarey(x) * sin(y*9)},     
{squarex(x) * sin(y*9) + squarey(x) * cos(y*9)} 
);
\addplot3 [z buffer=auto, fill=black!30, draw=black] table { 
x y z 
10 -1 -1 
10 1 -1 
10 1 1 
10 -1 1 
10 -1 -1 
};
\addplot3 [     
z buffer=auto, domain=-60:270, samples y=1,     
ultra thick, black, latex-] (     
10.5,     
{sin(x)*1.5},     
{cos(x)*1.5} );
\draw [ultra thick,-latex] (3.5,0,2) -- (6.5,0,2);
\node[rotate=-12] (label) at (5,0,2.7) {wave motion};
\end{axis} 
\end{tikzpicture}

}\hfill{}\subfloat[]{Other figure goes here

}

\caption{Torsional wave. a) a cuboid figure undergoing torsional         distortion
b) the bending and bucking in this bridge is caused by torsional waves}
\end{figure}

\end{document}

Edit: I did not make the tikz image, it has been adapted from Here

6

Oh wow, that's a really cool figure! I think you have mixed up the syntax for plotting table data, you used the one for files. To "repair" your code I create the file, alternatively you could adjust the syntax.

\documentclass[test]{report}
\usepackage[T1]{fontenc}
\usepackage[latin9]{luainputenc}
\setcounter{secnumdepth}{3}
\setcounter{tocdepth}{3}

\makeatletter
\usepackage{bohr}
\usepackage{carbohydrates}
\usepackage{chemfig}
\usepackage{tikz}
\usepackage{pgfplots}

\pgfplotsset{compat=1.12}

\@ifundefined{showcaptionsetup}{}{%
 \PassOptionsToPackage{caption=false}{subfig}}
\usepackage{subfig}
\makeatother

\usepackage{filecontents}
\begin{filecontents*}{mytable.dat}
x y z 
10 -1 -1 
10 1 -1 
10 1 1 
10 -1 1 
10 -1 -1 
\end{filecontents*}

\usepackage{babel}
\begin{document}
\begin{figure}
\subfloat[]{\begin{tikzpicture}[     
declare function={squarex(\t) =         
    (\t < 0.25) ? 1 : (             
        (\t < 0.5) ? (1 - (\t-0.25) * 8) : (                 
            (\t < 0.75) ? -1 : (-1 + (\t - 0.75) * 8)         
    )     
;},     
declare function={squarey(\t) =         
    (\t < 0.25) ? (-1 + \t*8) : (             
        (\t < 0.5) ? 1 : (                 
            (\t < 0.75) ? (1 - (\t - 0.5) * 8) : -1         
    )     
;} 
] 
\begin{axis}[    
axis equal image,      
z buffer=sort,
hide axis,      
domain=0:1, y domain = 0:10, samples y = 25,     
ylabel =y, xlabel=x,     clip=false 
]
\addplot3 [     
z buffer=none, domain=0:330, samples y=1,     
ultra thick, black, -latex] (     
-0.5,     
{sin(x)*1.5},     {cos(x)*1.5} 
);
\addplot3 [surf, shader=flat, fill=black!10, draw=black] (     
y,     
{squarex(x) * cos(y*9) - squarey(x) * sin(y*9)},     
{squarex(x) * sin(y*9) + squarey(x) * cos(y*9)} 
);
\addplot3 [z buffer=auto, fill=black!30, draw=black] table {mytable.dat};
\addplot3 [     
z buffer=auto, domain=-60:270, samples y=1,     
ultra thick, black, latex-] (     
10.5,     
{sin(x)*1.5},     
{cos(x)*1.5} );
\draw [ultra thick,-latex] (3.5,0,2) -- (6.5,0,2);
\node[rotate=-12] (label) at (5,0,2.7) {wave motion};
\end{axis} 
\end{tikzpicture}

}\hfill{}\subfloat[]{Other figure goes here.}

\caption{Torsional wave. a) a cuboid figure undergoing torsional         distortion
b) the bending and bucking in this bridge is caused by torsional waves}
\end{figure}

\end{document}

enter image description here

Torbjørn scooped me in adding the alternative, so his answer or the following code yields the same output.

\documentclass[test]{report}
\usepackage[T1]{fontenc}
\usepackage[latin9]{luainputenc}
\setcounter{secnumdepth}{3}
\setcounter{tocdepth}{3}

\makeatletter
\usepackage{bohr}
\usepackage{carbohydrates}
\usepackage{chemfig}
\usepackage{tikz}
 \usepackage{pgfplots}

\pgfplotsset{compat=1.12}

\@ifundefined{showcaptionsetup}{}{%
 \PassOptionsToPackage{caption=false}{subfig}}
\usepackage{subfig}
\makeatother

\usepackage{babel}
\begin{document}
\begin{figure}
\subfloat[]{\begin{tikzpicture}[     
declare function={squarex(\t) =         
    (\t < 0.25) ? 1 : (             
        (\t < 0.5) ? (1 - (\t-0.25) * 8) : (                 
            (\t < 0.75) ? -1 : (-1 + (\t - 0.75) * 8)         
    )     
;},     
declare function={squarey(\t) =         
    (\t < 0.25) ? (-1 + \t*8) : (             
        (\t < 0.5) ? 1 : (                 
            (\t < 0.75) ? (1 - (\t - 0.5) * 8) : -1         
    )     
;} 
] 
\begin{axis}[    
axis equal image,      
z buffer=sort,
hide axis,      
domain=0:1, y domain = 0:10, samples y = 25,     
ylabel =y, xlabel=x,     clip=false 
]
\addplot3 [     
z buffer=none, domain=0:330, samples y=1,     
ultra thick, black, -latex] (     
-0.5,     
{sin(x)*1.5},     {cos(x)*1.5} 
);
\addplot3 [surf, shader=flat, fill=black!10, draw=black] (     
y,     
{squarex(x) * cos(y*9) - squarey(x) * sin(y*9)},     
{squarex(x) * sin(y*9) + squarey(x) * cos(y*9)} 
);
\addplot3 [z buffer=auto, fill=black!30, draw=black] table[row sep=crcr] { 
x y z \\
10 -1 -1\\ 
10 1 -1 \\
10 1 1 \\
10 -1 1 \\
10 -1 -1 \\
};
\addplot3 [     
z buffer=auto, domain=-60:270, samples y=1,     
ultra thick, black, latex-] (     
10.5,     
{sin(x)*1.5},     
{cos(x)*1.5} );
\draw [ultra thick,-latex] (3.5,0,2) -- (6.5,0,2);
\node[rotate=-12] (label) at (5,0,2.7) {wave motion};
\end{axis} 
\end{tikzpicture}

}\hfill{}\subfloat[]{Other figure goes here

}

\caption{Torsional wave. a) a cuboid figure undergoing torsional         distortion
b) the bending and bucking in this bridge is caused by torsional waves}
\end{figure}

\end{document}
4

With table[row sep=\\] and a \\ at the end of each line it works (at least for me).

\documentclass[test]{report}
\usepackage[T1]{fontenc}
\usepackage[latin9]{luainputenc}
\setcounter{secnumdepth}{3}
\setcounter{tocdepth}{3}

\makeatletter
\usepackage{bohr}
\usepackage{carbohydrates}
\usepackage{chemfig}
\usepackage{tikz}
 \usepackage{pgfplots}

\pgfplotsset{compat=1.12}

\@ifundefined{showcaptionsetup}{}{%
 \PassOptionsToPackage{caption=false}{subfig}}
\usepackage{subfig}
\makeatother

\usepackage{babel}
\begin{document}
\begin{figure}
\subfloat[]{\begin{tikzpicture}[     
declare function={squarex(\t) =         
    (\t < 0.25) ? 1 : (             
        (\t < 0.5) ? (1 - (\t-0.25) * 8) : (                 
            (\t < 0.75) ? -1 : (-1 + (\t - 0.75) * 8)         
    )     
;},     
declare function={squarey(\t) =         
    (\t < 0.25) ? (-1 + \t*8) : (             
        (\t < 0.5) ? 1 : (                 
            (\t < 0.75) ? (1 - (\t - 0.5) * 8) : -1         
    )     
;} 
] 
\begin{axis}[    
axis equal image,      
z buffer=sort,
hide axis,      
domain=0:1, y domain = 0:10, samples y = 25,     
ylabel =y, xlabel=x,     clip=false 
]
\addplot3 [     
z buffer=none, domain=0:330, samples y=1,     
ultra thick, black, -latex] (     
-0.5,     
{sin(x)*1.5},     {cos(x)*1.5} 
);
\addplot3 [surf, shader=flat, fill=black!10, draw=black] (     
y,     
{squarex(x) * cos(y*9) - squarey(x) * sin(y*9)},     
{squarex(x) * sin(y*9) + squarey(x) * cos(y*9)} 
);
\addplot3 [z buffer=auto, fill=black!30, draw=black] table[row sep=\\] {%
x y z \\
10 -1 -1\\ 
10 1 -1 \\
10 1 1 \\
10 -1 1 \\
10 -1 -1 \\
};
\addplot3 [     
z buffer=auto, domain=-60:270, samples y=1,     
ultra thick, black, latex-] (     
10.5,     
{sin(x)*1.5},     
{cos(x)*1.5} );
\draw [ultra thick,-latex] (3.5,0,2) -- (6.5,0,2);
\node[rotate=-12] (label) at (5,0,2.7) {wave motion};
\end{axis} 
\end{tikzpicture}

}\hfill{}\subfloat[]{Other figure goes here

}

\caption{Torsional wave. a) a cuboid figure undergoing torsional         distortion
b) the bending and bucking in this bridge is caused by torsional waves}
\end{figure}

\end{document}
  • Yes. Was just about to add this to my answer... +1 of course. – marmot Jul 21 '18 at 15:08

Your Answer

By clicking “Post Your Answer”, you agree to our terms of service, privacy policy and cookie policy

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