Nadal, 32, lost his opening service game and trailed 2-0 in the first set before recovering well in Paris.
Nadal responded to reel off five straight games to assert his dominance.
Having gone two sets up on the back of big hitting from the baseline, sixth seed Anderson threw Schwartzman a lifeline in the contest while serving for the match at 5-4.
ZInedine Zidane : Une offre de 200 millions pour coacher le Qatar !
En octobre dernier, Didier Deschamps a prolongé son contrat jusqu'en 2020 avec la Fédération française de football . En France, l'Equipe fait référence au "discours d'un roi" au sujet de Zinédine Zidane .
Nadal quickly rallied before securing the tiebreaker on his second match point when Marterer fired long, celebrating with a trademark fist pump.
But Marterer, who was playing in the main draw here for the first time, moved into a 3-1 lead early in the third as he threatened to become the first man to take a set off Nadal at Roland Garros since his 2015 quarterfinal defeat by Djokovic.
But he kept fighting, forcing a tie-break only for Nadal to up the intensity once again and open up a 5-2 lead.
FACT CHECK: Did the Trump administration really 'lose' 1475 migrant children?
María Andrés de la Cruz was apprehended by Border Patrol agents in late May, shortly after she crossed the Rio Grande. The White House has wrongly blamed Democrats for forcing the Trump administration to separate children from parents.
Next up for the Spaniard is a last-eight meeting with Diego Schwartzman, who came from two sets down to see off Kevin Anderson, runner-up to Nadal in last year's US Open final.
The first went begging with a forehand long of his own, but Marterer's fight was finally over when he could not land a backhand, prompting Nadal to race to the net and congratulate the German on a fine effort.
Marterer was only the 11th man in 50 years of professional tennis to make the last 16 on debut at Roland Garros, and first since Nadal won the first of his record 10 titles in Paris in 2005.
New iPhone features to include ways to use it less
You can now set an ending time for do not disturb - for 1 hour, until a certain period, or when you leave a location or meeting. Time limits for particular apps will also be available to users, and parents can set those time limits for their children.